-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash.txt
More file actions
44 lines (34 loc) · 1.29 KB
/
bash.txt
File metadata and controls
44 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--------------------------------------------------------------------------------
BASH
$0 - Name of the script itself
$1, $2, etc. - Positional parameters
$* - Positional parameters as a single word (within double quotes)
$@ - Positional parameters as separate words (within double quotes)
$# - Number of positional parameters
$? - Exit status of the most recently executed command
$$ - Process ID of the shell
${1//[0-9]/} - Removes all digits from $1
${1//[!0-9]/} - Removes all except digits from $1
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
// Gets the script's source file pathname, strips it to just the path portion,
// cds to that path, then uses pwd to return the (effectively) full path of
// the script.
--------------------------------------------------------------------------------
CONDITIONAL ACTIONS
rm foobar && echo "Success"
rm foobar || echo "Fail"
rm foobar && echo "Success" || echo "Fail"
--------------------------------------------------------------------------------
EXAMPLES:
if [[ -z "$@" ]]; then
echo "Need arguments like: alfa1"
exit 1
fi
if [[ $1 == alpha* ]]; then
echo "ALPHA"
elif [[ $1 == beta* ]]; then
echo "BETA"
else
echo "Failed to detect alpha/beta"
exit 1
fi