Last active
April 8, 2020 07:45
-
-
Save hlapidez/0f2e40cc66f8aa351d9a1a9ee2e2ce39 to your computer and use it in GitHub Desktop.
Revisions
-
hlapidez revised this gist
Apr 8, 2020 . 1 changed file with 18 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ # ---------------------------------------------------------------------------- # How to check if a string begins with some value in bash # # more cool examples here: https://www.cyberciti.biz/faq/bash-check-if-string-starts-with-character-such-as/ # ---------------------------------------------------------------------------- # # Let us define a shell variable called vech as follows: vech="Bus" @@ -23,3 +24,18 @@ then else echo "No match" fi # ---------------------------------------------------------------------------- # Check number of arguments passed to a Bash script # # https://stackoverflow.com/questions/18568706/check-number-of-arguments-passed-to-a-bash-script # ---------------------------------------------------------------------------- if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" fi # Or if test "$#" -ne 1; then echo "Illegal number of parameters" fi -
hlapidez revised this gist
Apr 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # How to check if a string begins with some value in bash # # more cool examples here: https://www.cyberciti.biz/faq/bash-check-if-string-starts-with-character-such-as/ # # Let us define a shell variable called vech as follows: vech="Bus" -
hlapidez revised this gist
Apr 8, 2020 . 1 changed file with 12 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ # How to check if a string begins with some value in bash # # source: https://www.cyberciti.biz/faq/bash-check-if-string-starts-with-character-such-as/ # # Let us define a shell variable called vech as follows: @@ -11,4 +12,14 @@ vech="Bus" # The [[ used to execute the conditional command. It checks if $vech starts with “B” followed by any character. Set vech to something else and try it again: vech="Car" [[ $vech = B* ]] && echo "Start with B" [[ $vech = B* ]] && echo "Start with B" || echo "Not matched" # longer version with if input="xBus" if [[ $input = B* ]] then echo "Start with B" else echo "No match" fi -
hlapidez revised this gist
Apr 8, 2020 . No changes.There are no files selected for viewing
-
hlapidez created this gist
Apr 8, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ # How to check if a string begins with some value in bash # source: https://www.cyberciti.biz/faq/bash-check-if-string-starts-with-character-such-as/ # # Let us define a shell variable called vech as follows: vech="Bus" # To check if string “Bus” stored in $vech starts with “B”, run: [[ $vech = B* ]] && echo "Start with B" # The [[ used to execute the conditional command. It checks if $vech starts with “B” followed by any character. Set vech to something else and try it again: vech="Car" [[ $vech = B* ]] && echo "Start with B" [[ $vech = B* ]] && echo "Start with B" || echo "Not matched"