My 2 paisas

Posts Tagged ‘shell

With the help of Abhas Bhaiyya, I could write this shell script which checks if an ipaddress can be pinged.

#!/bin/sh

if [ `ping -c1 192.168.31.31 >/dev/null; echo $?` -eq 1 ]
then
echo “not able to ping”
fi

/dev/null is used here so that the output of the ping command is not compared with 1.
$? gives out the return code of the command.

‘!$’ is the right answer.

For example: $vim test.pl
$chmod +x !$
$./!$

So what is happening above is
first vim test.pl opens a file.
then after you have written a perl script, you would like to make it executable. There is no need for you to specify the file name again. You can just use !$.
In the third command again to execute the file, there is no need to mention the file name again. You just use !$ again.


Links that I liked to save

Blog Stats

  • 46,383 hits