Skip to content

Instantly share code, notes, and snippets.

@simongcc
Last active August 18, 2020 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simongcc/602b829dc871350b907e10b1cf6413b6 to your computer and use it in GitHub Desktop.
Save simongcc/602b829dc871350b907e10b1cf6413b6 to your computer and use it in GitHub Desktop.
Bash batch file notes
for file in *.po; do
po-to-xls ${file%.*}.po -o ${file%.*}.xlsx
done
# https://stackoverflow.com/questions/2664740/extract-file-basename-without-path-and-extension-in-bash
# $file is the file original name
# no extension: ${file%.*}.po
# s=/the/path/foo.txt
# echo "${s##*/}"
# foo.txt
# s=${s##*/}
# echo "${s%.txt}"
# foo
# echo "${s%.*}"
# foo
# zip folders individually
# https://stackoverflow.com/questions/20452384/how-to-compress-multiple-folders-each-into-its-own-zip-archive
for i in */; do
zip -r "${i%/}.zip" "$i";
done
# test statement
# https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php
# if then
# http://mywiki.wooledge.org/BashFAQ/031
if [ $1 = "load" ]; then
sudo launchctl load /Library/LaunchDaemons/homebrew.custom.httpd.plist
fi
if [ $1 = "unload" ]; then
sudo launchctl unload /Library/LaunchDaemons/homebrew.custom.httpd.plist
fi
if [ $1 = "reload" ]; then
sudo launchctl unload /Library/LaunchDaemons/homebrew.custom.httpd.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.custom.httpd.plist
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment