We have moved to www.dataGenX.net, Keep Learning with us.

Tuesday, November 27, 2012

Saving Shell Script with executable permissions: tips & tricks



In our tech routine we daily usually need to write small script to do task easily. Sometimes its irritating to edit/create and save and give the executable permissions.

What if when we create a file it have the executable permissions, Yes, we can do that with the help of umask but this will applicable on all files so don’t want that. So here is the solution….


First create this script and save it with name “vix”.


#!/bin/ksh

/usr/bin/touch $1
/usr/bin/chmod 700 $1    #you can give the required permissions
/usr/bin/vi $1


Simple, right?  
$1 is just your command line arguments (the names of the script you're going to edit/write), so you can call:

./vix scripta.sh  ...

instead of

vi scripta.sh  ...

and your script will be executable when you're done editing it. Silly and simplistic? Yes. Useful, too, if you're sick and tired of typing chmod 700 (or whatever) after every script you write :)





njoy the simplicity.......