I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
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
sh
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.
Just a coder and a dad. I love my family and I love to code!!!! started coding at 11, so I have 25 years under my belt. Still love learning about it every day. Black lives matter!
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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, addsh
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
, andwavToMp3
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.Nice comment!
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.