27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

first_param=$1<br />

second_param=$2<br />

shift; shift # Shift past first two positional params.<br />

remaining_params="$*"<br />

echo<br />

echo "first parameter = $first_param"<br />

echo "second parameter = $second_param"<br />

echo "remaining parameters = $remaining_params"<br />

# one<br />

# two<br />

# three four five<br />

echo; echo<br />

# Again.<br />

set −− $variable<br />

first_param=$1<br />

second_param=$2<br />

echo "first parameter = $first_param"<br />

echo "second parameter = $second_param"<br />

# one<br />

# two<br />

# ======================================================<br />

set −−<br />

# Unsets positional parameters if no variable specified.<br />

first_param=$1<br />

second_param=$2<br />

echo "first parameter = $first_param"<br />

echo "second parameter = $second_param"<br />

# (null value)<br />

# (null value)<br />

exit 0<br />

unset<br />

See also Example 10−2 and Example 12−40.<br />

The unset command deletes a shell variable, effectively setting it to null. Note that this command<br />

does not affect positional parameters.<br />

bash$ unset PATH<br />

bash$ echo $PATH<br />

bash$<br />

Example 11−15. "unsetting" a variable<br />

#!/bin/bash<br />

# unset.sh: Unsetting a variable.<br />

variable=hello<br />

echo "variable = $variable"<br />

# Initialized.<br />

unset variable<br />

# Unset.<br />

# Same effect as variable=<br />

echo "(unset) variable = $variable" # $variable is null.<br />

export<br />

exit 0<br />

Chapter 11. Internal Commands and Builtins 136

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!