I want to stop losing precious time when dealing with Linux/Unix's shell.
If I could get to understand it well, that would be great. Otherwise:
You see, it's these kind of things that cripple my Linux/Unix life.
As a programmer, I want to get much better at this. I suppose it's best to stay with the widely-used bash shell, but I might be wrong. Whatever tool I use, I need to understand it down to its guts.
What is the ultimate solution?
A shell script have syntax just like any other programming language. If you have any prior experience with any programming language like Python, C/C++ etc. it would be very easy to get started with it.
You can learn this language in this course called Linux Shell Scripting through many projects, which will take you around two weeks to a month to complete.
To navigate to your home directory, use "cd" or "cd ~" To navigate up one directory level, use "cd .." To navigate to the previous directory (or back), use "cd -" To navigate through multiple levels of directory at once, specify the full directory path that you want to go to.
Just for fun:
. run.sh
--- "Source" the code in run.sh. Usually, this is used to get environment variables into the current shell processes. You probably don't want this for a script called run.sh
.
./run.sh
--- Execute the run.sh
script in the current directory. Generally the current directory is not in the default path (see $PATH
), so you need to call out the relative location explicitly. The .
character is used differently than in item #1.
. ./run.sh
--- Source the run.sh
script in the current directory. This combines the use of .
from items #1 and #2.
sh run.sh
--- Use the sh
shell interpretor on run.sh
. Bourne shell is usually the default for running shell scripts, so this is probably the same as item #2 except it finds the first run.sh
in the $PATH
rather than the one in the current directory.
sh ./run.sh
--- And this is usually the same as #2 except wordier.
Command line interfaces, such as the various shell interpretors, tend to be very esoteric since they need to pack a lot of meaning into a small number of characters. Otherwise typing takes too long.
In terms of learning, I'd suggest using bash
or ksh
and don't let anyone talk you into something else until you are comfortable. Please don't learn with csh
or you will need to unlearn too much when you start with a Bourne-type shell later.
Also, crontab
entries are a bit trickier than other uses of shell. My guess is you lost time because your environment was set differently than on the command line. I would suggest starting somewhere else if possible.
Man pages are probably the "ultimate" solution. I'm always amazed at what gems they contain.
You can even use man bash
to answer some of the questions you raise in this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With