From acc9a73c018a28a9c8ead7b108dd1fdfee7a797b Mon Sep 17 00:00:00 2001 From: ksami Date: Fri, 2 Oct 2015 22:08:27 +0800 Subject: [bash/en] Improved descriptions --- bash.html.markdown | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index 08182c2c..d4f3d424 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -51,7 +51,7 @@ echo $Variable echo "$Variable" echo '$Variable' # When you use the variable itself — assign it, export it, or else — you write -# its name without $. If you want to use variable's value, you should use $. +# its name without $. If you want to use the variable's value, you should use $. # Note that ' (single quote) won't expand the variables! # String substitution in variables @@ -70,11 +70,11 @@ echo ${Foo:-"DefaultValueIfFooIsMissingOrEmpty"} # Builtin variables: # There are some useful builtin variables, like -echo "Last program return value: $?" +echo "Last program's return value: $?" echo "Script's PID: $$" -echo "Number of arguments: $#" -echo "Scripts arguments: $@" -echo "Scripts arguments separated in different variables: $1 $2..." +echo "Number of arguments passed to script: $#" +echo "All arguments passed to script: $@" +echo "Script's arguments separated into different variables: $1 $2..." # Reading a value from input: echo "What's your name?" @@ -108,8 +108,8 @@ fi # Expressions are denoted with the following format: echo $(( 10 + 5 )) -# Unlike other programming languages, bash is a shell — so it works in a context -# of current directory. You can list files and directories in the current +# Unlike other programming languages, bash is a shell so it works in the context +# of a current directory. You can list files and directories in the current # directory with the ls command: ls -- cgit v1.2.3 From 960ee4a1856db8eadb96277bb2422edfa8f2a81c Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 23:11:24 -0400 Subject: removing whitespace all over --- bash.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index d4f3d424..191f916a 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -252,7 +252,7 @@ grep "^foo.*bar$" file.txt grep -c "^foo.*bar$" file.txt # if you literally want to search for the string, # and not the regex, use fgrep (or grep -F) -fgrep "^foo.*bar$" file.txt +fgrep "^foo.*bar$" file.txt # Read Bash shell builtins documentation with the bash 'help' builtin: -- cgit v1.2.3 From f4022052471d6dc0a9c2fb8794e1352253b4c5ad Mon Sep 17 00:00:00 2001 From: Awal Garg Date: Wed, 14 Oct 2015 21:10:28 +0530 Subject: [bash/en] use $var with quotes in conditions --- bash.html.markdown | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index 191f916a..211d2944 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -90,17 +90,26 @@ else echo "Your name is your username" fi +# NOTE: if $Name is empty, bash sees the above condition as: +if [ -ne $USER ] +# which is invalid syntax +# so the "safe" way to use potentially empty variables in bash is: +if [ "$Name" -ne $USER ] ... +# which, when $Name is empty, is seen by bash as: +if [ "" -ne $USER ] ... +# which works as expected + # There is also conditional execution echo "Always executed" || echo "Only executed if first command fails" echo "Always executed" && echo "Only executed if first command does NOT fail" # To use && and || with if statements, you need multiple pairs of square brackets: -if [ $Name == "Steve" ] && [ $Age -eq 15 ] +if [ "$Name" == "Steve" ] && [ "$Age" -eq 15 ] then echo "This will run if $Name is Steve AND $Age is 15." fi -if [ $Name == "Daniya" ] || [ $Name == "Zach" ] +if [ "$Name" == "Daniya" ] || [ "$Name" == "Zach" ] then echo "This will run if $Name is Daniya OR Zach." fi -- cgit v1.2.3