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
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:
#!/bin/bash
function echoshit() {
echo "No parameter found or wrong parameter"
}
if [[ $1 == --trolli ]];
then
echo "trolli echoed"
else
echoshit;
fi
Adding parameters to script:
#!/bin/bash
function echoshit() {
echo "No parameter found or wrong parameter"
}
if [[ $1 == --trolli ]];
then
echo "trolli echoed"
else
echoshit;
fi
Read more: http://www.bashguru.com/2009/11/how-to-pass-arguments-to-shell-script.html
Ei kommentteja:
Lähetä kommentti