AIX 5L Basics (Unit 09) – Using Shell Variables

Variable – represents data whose value may change

HOME – /home/wltest
TERM = Terminal Type
PATH – Search Path

Set | pg – shows variables by page

PS1=$ – Primary Prompt
PS2=> – Secondary Prompt
SHELL = Korn Shell
TERM=vt220
xy=day

1. Assign variables (variablename=value)
Note: No spaces before or after the equal sign
2. Reference a variable (echo $variablename)
3. Delete variables (unset xy)

_$xy_ – spaces
${xy}long – no spaces

Command Substitution: $(command) or `command`
———————————-
Variable=”output from a command”
now=$(date) or now=`date`
HOST=$(hostname) or HOST=`hostname`
echo “Today is ‘date’ and ‘who | wc -l users are logged in”

Note: Only executes the command when it is set not each time it is run or accessed.

Quoting Metacharacters:
————————————
‘ ‘ – Single Quotes – Ignores all metacharacters between quotes (Literally)
echo ‘$HOME’ – output = $HOME

” ” – Double Quotes – Iqnores all metacharacters ecept $, `, |
echo “$HOME” – output = /home/wltest

\ – Backslash – Ignores the special menaing of the next character
echo \$HOME – output = $HOME

Command Line Parsing: (Sequence)
—————————————————–
1. Redirection >, >>, 2>
2. Command and Variable Substitution $var, $(cmd)
3. Wildcard expansion *, ?, []
4. Command Execution

ls $dir *.? 2>/dev/null | tee filelist.txt

echo * $HOME – Displays the files in the /home/wltest directory

Leave a Reply

Your email address will not be published. Required fields are marked *

*