torstai 10. joulukuuta 2015

Shellscripting like a boss

It is good idea to put all your shell script commands in a directory and export it to the path. In order to do this open up your .bashrc file of .profile

nano ~/.bashrc

Add this line to it 

export PATH=$PATH:~/scripts

It means in your home folder there should be a folder named scripts. Like /home/username/scripts.

Then reload your bashrc file 

source ~/.bashrc

And now you are ready for scripting. Add new file named hello to the script folder. 

Add this

echo My first program

Then in any directory type hello and your script executes.

Adding parameters to script:


function echoshit() {
    echo "No parameter found or wrong parameter"

if [[ $1 == --trolli ]];
  echo "trolli echoed"

Read more:

Ei kommentteja:

Lähetä kommentti