Some shell commands/Scripts

1. echo $((2>3)) //expressions

2. test 2 > 3 && echo “Yes” //condition check

3. read -p “Prompt” $variable1 $variable2 //reading from console

4. echo “today is $(date)”

5. var=10 //declaring variable, no space before or after =

6. declare -r y=10 //creating constant or read only variable

7. unset var //frees the variable

8. declare -i y=10 //creating int variable

9. find $HOME -name *.c //finding all c files inside home

10. printf “%s\n” “$varName” //prints

11. sleep 3 //sleeps for 3 sec

12. if condition //if condition

then

command1

command2

..

commandN

fi

13. if condition //if-else condition

then

command1

else

command2

fi

14.

if condition //if-else-if condition

then  command1

elif condition2

command2

elif condition3

command3

else

fi

15. Logical AND, && // Run second command only if first is successful.

16. Logical OR, || // Run second command only if first is successful.

17. grep text file.ext //search text inside a file

18. [ condition ] //condition checking similar to test

19. case $variable-name in

pattern1)

command1

commandN

;;

pattern2)

command1

;;

esac

20.

for var in item1 item2 … itemN

do

command1

command2

commandN

done

2. //declaring function

die()

{

echo “An error occurred.”

}

>die //call it

Reference : http://bash.cyberciti.biz/guide/Shebang    *click the right top arrows to move forward pages

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.