re: Shell scripts are awesome VIEW POST


I agree with you: shell scripts are awesome.

I'm calling them that though because you refer to "bash scripts" you're using in zsh. They type of script is defined by the shell that's running it (which is either the shell sourcing it with . or the shell its shebang tells it to execute).
I think that you're getting confused around the purpose of the shebang, because you talk about writing a PHP script with #!/usr/bin/php, which is great, it's fine, and as long as you make it executable (with `chmod +x ./urldecode') there's no reason to wrap it in a shell function. Instead of putting it into some "snippets" directory, put it in somewhere on your path... or better yet, add

export PATH=$HOME/settings/snippets:$PATH

to your shell config.
Then all your PHP snippets that are marked executable and have a valid shebang will work automatically.

This has the added benefit that you can use it in another shell script and know that as long as you include the full path it'll work. If you write an alias or a shell function, and then try to use it in another script, you'll see unexpected things happen depending on circumstances. For instance if you made a cron job that expected urldecode to be your shell function, there's a good chance it won't be available.

I'd also really recommend making your function or alias names consistent: removeEmptySubdirs, flattenSubfolders, genvideothumb, and wavToMp3 all have different capitalisation and abbreviations. I know it'll autocomplete for you, but it's extra cognitive load, and from personal experience... my brain gets full.


See this is what I love, you taught me so much! I knew that I only had a over all idea of what I was doing with "Shell" scripts. So thank you for clarifying all of that. I'm going to update my post with this great information!

Also I KNEW someone would all me on the casing ha ha. I was tempted to update it in the post but I got lazy.

Code of Conduct Report abuse