LDP/LDP/guide/docbook/abs-guide/ex15.sh

37 lines
578 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2002-07-22 15:11:51 +00:00
# Naked variables
2001-07-10 14:25:50 +00:00
echo
# When is a variable "naked", i.e., lacking the '$' in front?
2001-09-04 13:27:31 +00:00
# When it is being assigned, rather than referenced.
2001-07-10 14:25:50 +00:00
# Assignment
a=879
2002-07-22 15:11:51 +00:00
echo "The value of \"a\" is $a."
2001-07-10 14:25:50 +00:00
# Assignment using 'let'
let a=16+5
2002-07-22 15:11:51 +00:00
echo "The value of \"a\" is now $a."
2001-07-10 14:25:50 +00:00
echo
2005-05-08 20:09:31 +00:00
# In a 'for' loop (really, a type of disguised assignment):
2002-07-22 15:11:51 +00:00
echo -n "Values of \"a\" in the loop are: "
2001-07-10 14:25:50 +00:00
for a in 7 8 9 11
do
echo -n "$a "
done
echo
echo
2005-05-08 20:09:31 +00:00
# In a 'read' statement (also a type of assignment):
2001-07-10 14:25:50 +00:00
echo -n "Enter \"a\" "
read a
2002-07-22 15:11:51 +00:00
echo "The value of \"a\" is now $a."
2001-07-10 14:25:50 +00:00
echo
exit 0