run a script
Make a script runnable and run it, or run it in the shell you are in.
Steps
-
chmod +x script.shlet it be run
-
./script.shrun it from its folder
-
bash script.shrun it with bash, even without the x
-
head -1 script.shits first line, #!/usr/bin/env bash, says what runs it
-
source script.shrun it in this shell, so its cd and variables stay
Notes
- "bad interpreter" with ^M: see "fix windows line endings".
Commands used
chmodbashsource
Each has a page in lore: lore chmod opens it.
Related recipes
- add a folder to the pathLet the shell find programs in a folder, for good, and reload the settings without logging out.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
- ask for input in a scriptAsk yes or no, read a password without showing it, or wait for an answer with a time limit.