Shell programming
-
Upload
khangminh22 -
Category
Documents
-
view
1 -
download
0
Transcript of Shell programming
Shell programming
• Shell is the Linux command interpreter• Often interact with users: command
• Shell reads commands from the keyboard or file
• Linux: kernel executing the command
• Shell script• Shell programs: sequence of commands
Create shell program
• Use text editors• Vi, emacs, nano, gedit
• Content: linux command
• Commands in the same line: separated by ;
• Change permissions:• chmod o + x file_name
• Execute:• bash file_name
• sh file_name
• ./ten_file
Example
• $nano first # My first shell script clear
echo "Hello $USER"
echo "Today is \c ";date
echo "Number of user login : \c" ; who | wc –l
echo "Calendar" • $ chmod 755 first
• $./first
Variable
• System variable:• Created and managed by Linux.• Variable names are uppercase
• Variable created by user:• Created and managed by users• Variable names are lowercase
• View or access variable values:• $name_ variable• echo $HOME• echo $USERNAME• Must have $ sign before variable name
Variable created by user
• How to use• name_variable=value
• Print • echo $name_variable
• Example• No=10
• Echo $No
Rules
• Variable names are case sensitive
• Variable names must begin with a character• HOME
• SYSTEM_VERSION
• no
• Vech
• No space between operator = when assigning values to variables• no=10 # correct
• no =10 # wrong
• no = 10 # wrong