Notes for Computer Information Technology 160
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sep21-conditionals.md 1.0KB

September 24 - Conditionals

$ man bash # open the man page for bash

1443g      # go to line 1443 for conditional expressions

Spaces in files and commands

Example: a folder exists "/tmp/foo bar"

Wrong: ls /tmp/foo bar

Correct: ls /tmp/foo\ bar

Also Correct: ls "/tmp/foo bar"

Argument special characters

$ test -z "hello"

$# = 2
$@ = "-z" "hello"
$* = "-z hello"
$0 = test
$1 = -z
$2 = "hello"

Stdout vs Stderr

echo "23" # 23 goes to stdout, 0 goes to stderr
exit "23" # 23 goes to stderr, nothing goes to stdout

I/O (input and output) Redirection and Piping

the command doesn’t care where stdin came from or where stdout is going

$ ls > file.test # run ls and put the output in file.test

$ sort < file.test # run sort with file.test as stdin

$ cat realfile fakefile > cat_stdout 2> cat_stderr # 2> redirects stderr

$ echo "new contents" >> file # append to file

Edit a scratch file with EOF

$ cat <<EOF | sort # edit a scratch file and pipe to sort
>input
>more input
>EOF