Faster shell scripting

While scripting makes  several task easier , the complete process of writing scripts take quite some time. To make scripting faster we can combine the common processes while writing a script. Starting a script include making a new text file with or without '.sh' extension . Always the first line will include name of the bash compiler i.e !#/bin/bash. After completing the script it definitely need to be made executable  .

The following script does all the above in one go.


-------------------------------------------------------------------------------------------------------------------------------------------------
HOW THIS SCRIPT WORKS:
The script is very simple and self explaining , moreover comments are provided to make more clarity. 
$USER is a special variable which contains the name of the user.
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
#!/bin/bash

#for creating bash document with necessary title and permission


#creating new bash file in "/home/$USER/BASH".Change this to correct path in your system.
> /home/$USER/BASH/"$*"

#writing compiler name to the file.Please correct the path here too.
echo "#!/bin/bash" >> /home/$USER/BASH/"$*"

#making the file executable
chmod 755 /home/$USER/BASH/"$*"

#opening the file in gedit.Change this to your faviourite text editor (emacs, vim etc).Please correct the path here also.
gedit /home/$USER/BASH/"$*"

-------------------------------------------------------------------------------------------

Script is named cbd in my system ( short form for create bash doc ) . Now suppose if you want to start a  new script named fast.sh, execute cbd fast.sh in terminal . fast.sh file will opened in your faviourite text editor , with necessary permission and name of the compiler written. Just complete fast.sh script , save it and run it .(make sure you change the path name to the correct one )

Happy scripting !!



Enjoy Linux !!

Dont know what to do with these codes?? click here

No comments:

Post a Comment