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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

echo 'IFS=":", using "$@"'<br />

c=0<br />

for i in "$@"<br />

do echo "$((c+=1)): [$i]"<br />

done<br />

echo −−−<br />

echo 'IFS=":", using $@'<br />

c=0<br />

for i in $@<br />

do echo "$((c+=1)): [$i]"<br />

done<br />

echo −−−<br />

var=$@<br />

echo 'IFS=":", using $var (var=$@)'<br />

c=0<br />

for i in $var<br />

do echo "$((c+=1)): [$i]"<br />

done<br />

echo −−−<br />

echo 'IFS=":", using "$var" (var=$@)'<br />

c=0<br />

for i in "$var"<br />

do echo "$((c+=1)): [$i]"<br />

done<br />

echo −−−<br />

var="$@"<br />

echo 'IFS=":", using "$var" (var="$@")'<br />

c=0<br />

for i in "$var"<br />

do echo "$((c+=1)): [$i]"<br />

done<br />

echo −−−<br />

echo 'IFS=":", using $var (var="$@")'<br />

c=0<br />

for i in $var<br />

do echo "$((c+=1)): [$i]"<br />

done<br />

echo<br />

# Try this script with ksh or zsh −y.<br />

exit 0<br />

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

# This example script by Stephane Chazelas,<br />

# and slightly modified by the document author.<br />

The $@ and $* parameters differ only when between double quotes.<br />

Example 9−8. $* and $@ when $IFS is empty<br />

#!/bin/bash<br />

# If $IFS set, but empty,<br />

Chapter 9. Variables Revisited 77

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

Saved successfully!

Ooh no, something went wrong!