How to write a Bash shell script - by example
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Re: How to write a Bash shell script - by example
The script the user invokes should be in /usr/bin. The other scripts should go to /usr/lib/foo. Non-executable files might instead go to /usr/share/foo. You can look at Linux Mint's programs like Update Manager that are Python scripts, where they store which kind of files: https://github.com/linuxmint/mintupdate/tree/master/usr
Re: How to write a Bash shell script - by example
Thank you for that, Habitual! Because of this encouragement and example, I've just created my first useful and working bash script :Habitual wrote:...Code: Select all
#!/bin/bash # Purpose: Inserts #!/bin/bash into a file and makes it executable # Usage: scriptname /path/to/file.sh # Author: JJ/Habitual # Date: Tue Jul 19, 2011 # Version: 1311133977 # Disclaimer: Use it, abuse it, just don't lose it. MINPARAMS=1 if [ -n "$1" ] then echo "#!/bin/bash" > $1 chmod 700 "$1" echo File $1 is now an executable and ready to be edited. fi if [ $# -lt "$MINPARAMS" ] then echo Usage: `pwd`/`basename $0` /path/to/script.sh fi exit 0
Enjoy! Now let's code something!!!
Code: Select all
#!/bin/bash
# Purpose : Updates the user.js folder in the firefox profile directory
# Usage : Close Firefox, then run script ./firefox.user.js.sh Firefox_profile_name. If no argument is added, it will use the default profile.
# Author : Lemongrass
# Date : 2017.01.14.
# Version : 0.1.
# Disclaimer : Only for GNU/Linux. Use it at your own risk.
MAXPARAMS=1
if [ $# -gt "$MAXPARAMS" ]
then
echo "Too many parameters. Usage: close Firefox, then run script ./firefox.user.js.sh Firefox_profile_name. If no argument is added, the default profile will be used."
exit 0
fi
if [ -n "$1" ]
then
rm -rf ~/.mozilla/firefox/????????.$1/user.js
git clone https://github.com/pyllyukko/user.js
mv user.js ~/.mozilla/firefox/????????.$1
else
rm -rf ~/.mozilla/firefox/????????.default/user.js
git clone https://github.com/pyllyukko/user.js
mv user.js ~/.mozilla/firefox/????????.default
fi
exit 0
#EOF
Re: How to write a Bash shell script - by example
Thanks to all who contribute{d} to the end result.Lemongrass38 wrote:Thank you for that, Habitual! Because of this encouragement and example, I've just created my first useful and working bash script :
I'm pretty certain I stole it off the 'net and ran it through my Linux Chop Shop.
Re: How to write a Bash shell script - by example
Still a great thread for us newbies, so I am going to bump it back up.