Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Bash (Unix shell)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Examples ==== With the {{code|:?|bash}} parameter expansion, an unset or null variable can halt a script. * ex.sh *: <syntaxhighlight lang="bash"> #!/bin/bash bar="foo is not defined" echo "${foo:?$bar}" echo this message doesn't print </syntaxhighlight> *: <syntaxhighlight lang="console"> $ ./ex.sh ./ex.sh: line 3: foo: foo is not defined </syntaxhighlight> Reliably printing the contents of an array that contains spaces and newlines first in a portable syntax, and then the same thing in Bash. Note that in Bash, the number of spaces before the newline is made clear. : <syntaxhighlight lang="console"> $ # In POSIX shell: $ array=( "a" "b" " > c " ) $ printf ',%s,\n' "${array[@]}" ,a, , b, , c, </syntaxhighlight> : <syntaxhighlight lang="bash"> # In Bash: declare -p array declare -a array=([0]="a" [1]=" b" [2]=$' \n c ') </syntaxhighlight> Printing an error message when there's a problem. * error.sh *: <syntaxhighlight lang="bash"> if ! lsblk | grep sdb then echo Error, line $LINENO fi </syntaxhighlight> *: <syntaxhighlight lang="console"> $ ./error.sh Error, line 130 </syntaxhighlight> Using [[xtrace]]. If errexit had been enabled, then {{code|echo quux|bash}} would not have been executed. * test.sh *: <syntaxhighlight lang="bash"> #!/bin/bash set -x foo=bar; echo $foo false echo quux </syntaxhighlight> *: <syntaxhighlight lang="console"> $ ./test.sh + foo=bar + echo bar bar + false + echo quux quux </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Bash (Unix shell)
(section)
Add topic