Jump to content

Bash (Unix shell): Difference between revisions

no edit summary
No edit summary
Line 100: Line 100:
===Wait===
===Wait===
Add <code>wait</code> at the end of a script to wait for all subprocesses.
Add <code>wait</code> at the end of a script to wait for all subprocesses.
===Brace Expansion===
When you type the following:
<syntaxhighlight lang="bash">
echo {red,green,blue}_apple
</syntaxhighlight>
bash will print out
<pre>
red_apple green_apple blue_apple
</pre>
If you want to save this into a variable, you can save it as an array:
<syntaxhighlight lang="bash">
APPLES=({red,green,blue}_apple)
echo "${APPLES[@]}"
</syntaxhighlight>


==dirname==
==dirname==
Line 128: Line 144:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'
PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'
</syntaxhighlight>
==Brace Expansion==
When you type the following:
<syntaxhighlight lang="bash">
echo {red,green,blue}_apple
</syntaxhighlight>
bash will print out
<pre>
red_apple green_apple blue_apple
</pre>
If you want to save this into a variable, you can save it as an array:
<syntaxhighlight lang="bash">
APPLES=({red,green,blue}_apple)
echo "${APPLES[@]}"
</syntaxhighlight>
</syntaxhighlight>