Difference between revisions of "Bash Shell Script Examples"
From Free Knowledge Base- The DUCK Project: information for everyone
(Created page with "== Add Pause Prompt In a Shell Script == Use "read". There is no pause command under bash shell. #!/bin/bash echo $1 read -p "Press [Enter] key to continue." The sampl...") |
|||
Line 1: | Line 1: | ||
− | == Add Pause Prompt In a Shell Script == | + | === Add Pause Prompt In a Shell Script === |
Use "read". There is no pause command under bash shell. | Use "read". There is no pause command under bash shell. | ||
Line 8: | Line 8: | ||
The sample script above shows what is entered as a command line parameter and then pauses, waiting for the user to press the ENTER key to continue. This creates a PAUSE. | The sample script above shows what is entered as a command line parameter and then pauses, waiting for the user to press the ENTER key to continue. This creates a PAUSE. | ||
+ | |||
+ | === Require command line parameters === | ||
+ | |||
+ | see example: | ||
+ | if [ -z $1 ] || [ -z $2 ] ; then | ||
+ | echo "newuser: too few arguments" | ||
+ | echo "Usage: newuser [username] [uid]" | ||
+ | echo "Adds a new robotz.com customer, for use by admin@robotz.com only." | ||
+ | else | ||
+ | useradd -r $1 -d /home/$1 -m -n -u $2 | ||
+ | fi | ||
Revision as of 22:38, 13 February 2015
Add Pause Prompt In a Shell Script
Use "read". There is no pause command under bash shell.
#!/bin/bash echo $1 read -p "Press [Enter] key to continue."
The sample script above shows what is entered as a command line parameter and then pauses, waiting for the user to press the ENTER key to continue. This creates a PAUSE.
Require command line parameters
see example:
if [ -z $1 ] || [ -z $2 ] ; then echo "newuser: too few arguments" echo "Usage: newuser [username] [uid]" echo "Adds a new robotz.com customer, for use by admin@robotz.com only." else useradd -r $1 -d /home/$1 -m -n -u $2 fi