Bourne Shell Prompt CIS 218. BASH Prompt Prompt is controlled via a special shell variable PS1, PS2, PS3 and PS4. If set, the value is executed as a command.

Slides:



Advertisements
Similar presentations
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Advertisements

Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Using Linux Commands 2 Lab#5
Using Linux Commands 2 Lab#5. Sort command Sort the lines of text files. $ sort fileName by default it will sort in normal order(alphabetical 0-9 A-Z.
Or CMD/BATCH.  Title this comand makes the cmd prompt’s title whatever you would like it to be.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Ch 71 Using ATTRIB, SUBST, XCOPY, DOSKEY, and the Text Editor.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
Introduction to Shell Script Programming
UNIX Unbounded 5th Edition Amir Afzal Chapter 3 Getting Started
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
An Introduction to Unix Shell Scripting
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CS 497C – Introduction to UNIX Lecture 7: General-Purpose Utilities Chin-Chih Chang
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
1 ADVANCED MICROSOFT EXCEL Lesson 9 Applying Advanced Worksheets and Charts Options.
UNIX and Shell Programming (06CS36) Unit 1 Continued… Shrinivas R. Mangalwede Department of Computer Science and Engineering K.L.S. Gogte Institute of.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
WORKBOOK FORMATTING Nolan Tomboulian Tomboulian.wikispaces.com HOW THINGS LOOK CELL COLORFONT COLOR CELL BORDERSFONT SIZE CELL SIZEFONT.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
CS465 - UNIX The Bourne Shell.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
Workbook 6 – Part 2 The Bash Shell
De Anza College Instructor: Clare Nguyen
Introduction to Computer Programming
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
Chapter Three The UNIX Editors.
40 Years and Still Rocking the Terminal!
Chapter Six Introduction to Shell Script Programming.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
N ATIONAL E NERGY R ESEARCH S CIENTIFIC C OMPUTING C ENTER Charles Leggett Colors in the Message Service ATLAS software workshop March Architecture.
1 Week # 4 Introduction to PDM PDM is a workbench environment that lets programmers and system operators navigate the three levels of the AS/400’s object-based.
Project Assignment Snake Game/Car Acceleration Meter Min 10 Pages 10 min Presentation Max 5 group members Submitting Date: lab 2:Dec 27, 2014 Lab 3: Dec.
Linux Administration Working with the BASH Shell.
Implementation of a simple shell, xssh
Introduction to Shells
Implementation of a simple shell, xssh (Section 1 version)
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
CSC201: Computer Programming
Implementation of a simple shell, xssh
Guide To UNIX Using Linux Third Edition
Introduction to Scripting
John Carelli, Instructor Kutztown University
Linux Shell Script Programming
LPI Linux Certification
Presentation transcript:

Bourne Shell Prompt CIS 218

BASH Prompt Prompt is controlled via a special shell variable PS1, PS2, PS3 and PS4. If set, the value is executed as a command prior to issuing each primary prompt. PS1 - This parameter is used as the primary prompt string. The default is: \s-\v\$. PS2 - The parameter is used as line continuation. The default is: > PS3 - The value of this parameter is used as the prompt for the select command. PS4 - This parameter is displayed during an execution trace (sh –x). The default is + Under bash, you can set your prompt by changing the value of the PS1 environment variable, as follows: export PS1="> " Changes take effect immediately, and can be made permanent by placing the "export" definition in your ~/.bashrc file. PS1 can contain any amount of plain text that you'd like. Most custom prompts contain information like the current username, working directory, or hostname. For example, the following prompt will display your username and hostname: $ export > “ Note: we insert the username and hostname into the prompt by using special backslash-escaped character sequences that bash replaces with specific values when they appear in the PS1 variable sequences: "\u" (for username) and "\H" (for the first part of the hostname).

BASH Prompt Examples You display the command prompt(s) as follows: echo $PS1 You modify the command prompt(s) by assigning a new value to PS1: PS1="Hello World : " Set the prompt so that it can display today’d date and hostname: PS1="\d \h $ “ Set the prompt to display date/time, hostname and current directory: $ PS1="[\d \t ] $ "

BASH Prompt control characters SequenceDescription \aThe ASCII bell character (you can also type \007) \dDate in "Wed Sep 06" format \eASCII escape character (you can also type \033) \hFirst part of hostname (such as "mybox") \HFull hostname (such as "mybox.mydomain.com") \jThe number of processes you've suspended in this shell by hitting ^Z \lThe name of the shell's terminal device (such as "ttyp4") \nNewline \rCarriage return \sThe name of the shell executable (such as "bash") \tTime in 24-hour format (such as "23:01:01") \TTime in 12-hour format (such as "11:01:01") in 12-hour format with am/pm \uYour username \vVersion of bash (such as 2.04) \VBash version, including patchlevel \wCurrent working directory (such as "/home/drobbins") \WThe "basename" of the current working directory (such as "drobbins") \!Current command's position in the history buffer \#Command number (this will count up at each prompt, as long as you type something) \$If you are not root, inserts a "$"; if you are root, you get a "#" \xxxInserts an ASCII character based on three-digit number xxx (replace unused digits with zeros, such as "\007") \\A backslash \[This sequence should appear before a sequence of characters that don't move the cursor (like color escape sequences). This allows bash to calculate word wrapping correctly. \]This sequence should appear after a sequence of non-printing characters.

BASH Prompt Colorization Adding color is simple; all you do is add special escape sequences that'll be recognized by the terminal (rather than bash) and cause it to display certain parts of the text in color. Standard Linux terminals and X terminals allow you to set the foreground (text) color and the background color, and also enable "bold" characters if so desired. We get eight colors to choose from. Colors are selected by adding special sequences to PS1 -- basically sandwiching numeric values between a "\e[" (escape open-bracket) and an "m". If more than one numeric code, separate each code with a semicolon. Example color code: "\e[0m“ When we specify a zero as a numeric code, it tells the terminal to reset foreground, background, and boldness settings to their default values. You'll want to use this code at the end of your prompt, so that the text that you type in is not colorized.

Color chart To add colors to the shell prompt use the following export command syntax: export '\e[x;ym $PS1 \e[m' Where: \e[ Start color scheme x;y Color pair to use (x;y) $PS1 is your shell prompt \e[m Stop color scheme x is 0 for regular, 1 for highlight. y is the color you'd like to use, and find the corresponding foreground (30-37) and background (40-47) numbers. Foreground: 30 - Black, 31 - Red, 32 - Green, 33 - Yellow, 34 - Blue, 35 - Purple, 36 - Blue/Green, 37 – White Background: 40 - Black, 41 - Red, 42 - Green, 43 - Yellow, 44 - Blue, 45 - Purple, 46 - Blue/Green, 47 – White

BASH Prompt Color Examples To set a red color prompt, type the command: export \W]\$ \e[m “ For example, if you like green on a normal black background, the numbers are 32 and 40. Then add the appropriate color codes take your prompt: export PS1="\e[32;40m\w> “ After bash prints the working directory, set the color back to normal with a "\e[0m" sequence: export PS1="\e[32;40m\w> \e[0m“ export PS1="\[\e[32;1m\]\w> \[\e[0m\]" export \[\e[0m\]"

tput command The tput utility uses the terminfo database to make the values of terminal-dependent capabilities to initialize or reset the terminal, or return the long name of the requested terminal type. tput outputs a string if the attribute (capability name) is of type string, or an integer if the attribute is of type integer. You can also use tput command display pecfic comands to a RED prompt follows (depends on termial type): export PS1="\[$(tput setaf $ \[$(tput sgr0)\]“ tput bold - Bold effect tput rev - Display inverse colors tput sgr0 - Reset everything tput init Initialize the terminal according to the type of terminal in the environmental variable TERM. tput -Tvt100 reset Reset an vt100 terminal. tput cup 0 0 Send the sequence to move the cursor to row 0, column 0, known as the "home" cursor position). tput clear Echo the clear-screen sequence for the current terminal. tput cols Print the number of columns for the current terminal. tput -Tvt100 cols Print the number of columns for the 450 terminal. bold=`tput smso` offbold=`tput rmso` Set the shell variables bold, to begin stand-out mode sequence, and offbold, to end standout mode sequence, for the current terminal. This might be followed by a prompt: echo "${bold}Please type in your name: ${offbold}\c" tput hc Set exit code to indicate if the current terminal is a hard copy terminal. tput cup 23 4 Send the sequence to move the cursor to row 23, column 4. tput cup Send the terminfo string for cursor-movement, with no parameters substituted. tput longname Print the long name from the terminfo database for the type of terminal specified in the environmental variable TERM. tput setaf {CODE}- Set foreground color, see color {CODE} below tput setab {CODE}- Set background color, see color {CODE} below {code} 0=Black, 1=Red, 2=Green, 3=Yellow, 4=Blue, 5=Magenta, 6=Cyan, 7=White

tset tset initializes terminals. tset first determines the type of terminal that you are using. This determination is made in the following order using the first terminal type found. 1. The terminal argument specified on the command line. 2. The value of the TERM environmental variable. 3. (BSD systems only.) The terminal type associated with the standard error output device in the /etc/ttys file. 4. The default terminal type, ``unknown''. tset options -q The terminal type is displayed to the standard output, and the terminal is not initialized in any way. -I Do not send the terminal or tab initialization strings to the terminal. -Q Don't display any values for the erase, interrupt and line kill characters. -V reports the version of ncurses which was used in this program, and exits. -i Set the interrupt character to ch. -k Set the line kill character to ch. -m Specify a mapping from a port type to a terminal. See below for more information. -r Print the terminal type to the standard error output. -s Print the sequence of shell commands to initialize the environment variable TERM to the standard output. The arguments for the -e, -i, and -k options may either be entered as actual characters or by using the `hat' notation, i.e. control-h may be specified as ``^H'' or ``^h''. To enter the terminal type and information about the terminal's capabilities into the shell's environment, this is done using the -s option as follows.login (csh) or.profile (bash) files: eval `tset -s options... ` When invoked as reset command, tset sets cooked and echo modes, reset

stty The stty command is used for changing the settings of a Unix computer terminal. This command is used to change keystrokes, irregular character handling, and more. stty gives a full set of features that are also available sttylist stty settings stty erase ^H Let the key combination Ctrl+H (in caret notation ^H) erase stty -aList all terminal attributes stty -g Save all current terminal settings in stty readable format. stty -echo Turn off screen echo (like password entry) stty -F `tty` rows 35 columns 59 To change the row and column size of your pseudo terminal stty -raw Set terminal to "uninitialized" mode stty saneRestore terminal device to normal settings

Making prompt settings permanent $ vi.bash_profile OR $ vi.bashrc Append export line: export \W]\$ \e[m" Save and close the file.