With BASH scripting, sometimes it's easier to reinvent the wheel! That's not always the case, of course, and there are many useful built-in special variables that we can use in our scripts. In this video we'll go over some of the more useful ones, and then look at how we can build our own just as easy. BASH is so flexible, it's easy to worry you're doing things the wrong way. The good news? There's no wrong way.
As promised, here are the variables we covered:
$0 - the name of the script itself
$* - all of the arguments as a single string
$$ - the PID of the running shell (or script)
$? - the error code of the LAST executed command
$HOME - home directory of the user running the script
$USER - user name of the user running the script
$PWD - the "present working directory" (directory we're in)
$EPOCHSECONDS - number of seconds since Jan 1, 1970
$EPOCHREALTIME - number of seconds since Jan 1, 1970, to the sixth decimal place!
$HOSTTYPE - system architecture
$OSTYPE - running OS (like "gnu-linux")
$MACHTYPE - system architecture and os
There are more built-in environment variables, but the larger point of this video was learning that lots of the information can also be pulled into the script using a call to an external program. So even if you don't remember a particular variable name -- just create your own!
#linux #bash #scripting
For regular info on what I'm doing, sign up for my newsletter!
https://snar.co/newsletter
All My Online Homes are Here:
https://shawnp0wers.com
Check out my comic!
/ mybigroundworld