Shell Programming
A Necessity for all Programmers
Writing Basic Commands and Scripts
Nagesh Karmali | Firuza Karmali
Department of Computer Science and Engineering
IIT Bombay
You will learn to ...
• Use basic commands
• Combine commands
• Read and understand an unknown command
• Execute script
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 2/8
Basic Commands
• List directory contents: ls
• Today’s date and time: date
• Show logged in user: who
• Show User ID: whoami
• Display line of text: echo
• Reading/Writing from/to file: cat
• Help: man
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 3/8
Combining Commands
• Can combine multiple commands
• Using ;
• date; who
• echo ”hello ”; whoami
• echo -n ”hello ”; whoami
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 4/8
Writing first script
• Create file.sh
cat > file.sh
#!/bin/sh
echo -n "hello "; whoami
• Make script executable
chmod +x file.sh
• Execute the script
./file.sh
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 5/8
Looking for help – man pages
• Reference manuals – Used for finding more information about any command
• Syntax: man <command>
• Examples
• man man: shows how to use man pages
• man ls: displays man page for the ls command
• Structure
• name
• synopsis
• description
• options
• return value
• exit status
• author
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 6/8
Now, you can ...
• Use commands for displaying
• directory contents
• today’s date
• logged in user
• display text
• Combine commands
• Execute scripts
• Get help for commands
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 7/8
Thank you
1
Shell Programming – A Necessity for all Programmers By Nagesh | Firuza 8/8