Linux Notes
apt - Advanced Package Tool
Useful commands for writing shell
script
`set -e` The set -e option instructs bash to immediately exit if any command [1]
has a non-zero exit status. You wouldn't want to set this for your command-line shell,
but in a script it's massively helpful.
Useful variables
-
$@
in Bourne-like shells, in list contexts expands to all the positional parameters as separate arguments. ```shell $> vi script.shscript.sh
#! /bin/sh - exec “$@”
$> script.sh ‘echo’ ‘a b’ ‘x y’
It will call exec with echo, a b
, and x y
as arguments which will execute echo
(in most sh implementations, /bin/echo as opposed to the echo shell builtin) in the
same process that was previously running the shell interpreting your script with some test and x y as arguments.
```text
command 2> error.log: This redirects StdErr (standard error) of the command to the file error.log. The standard output (StdOut) remains unchanged and continues to be displayed on the terminal.
command 1> out.log: This redirects StdOut (standard output) of the command to the file out.log. The standard error (StdErr) remains unchanged and continues to be displayed on the terminal.
command > error.log: This redirects StdOut (standard output) of the command to the file error.log. However, the standard error (StdErr) is not redirected and continues to be displayed on the terminal.
This is a sapling 🌱 in my digital garden 🏡.
Notes mentioning this note
There are no notes linking to this note.