06-02-2015
Oh, come on. Let's stop beating around the bush...
The shell knows that underscore (_) and period (.) are not the same thing, and you should recognize that too.
If a shell variable name is to be expanded in a string where the variable name is immediately followed by a character that can also be part of a shell variable name, the variable name must be surrounded by braces ({ and }) to keep the following character from being interpreted as part of the variable name. Valid simple shell variable names are strings of one or more alphanumeric characters and underscores where the 1st character is not numeric.
So, if three shell variables are to be expanded separated by underscores, you need braces to keep the underscores separate from the variable names. But if three shell variables are to be expanded separated by periods, the braces are not needed (but won't hurt if they are included).
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello.
Consider the following magic words:
# ls `which adduser`
ls: /usr/sbin/adduser: No such file or directory
#
Hmmm...
Then:
# ls /usr/sbin/adduser
/usr/sbin/adduser
#
Now what?
Unforunately this little sniippet is used in my debian woody server's mysql pre install script.... (2 Replies)
Discussion started by: osee
2 Replies
2. UNIX for Dummies Questions & Answers
I have a script with a find command using xargs to copy the files found to another directory. The find command is finding the appropriate file, but it's not copying. I've checked permissions, and those are all O.K., so I'm not sure what I'm missing. Any help is greatly appreciated.
This is... (2 Replies)
Discussion started by: mpflug
2 Replies
3. OS X (Apple)
I've been trying to figure this out since last night, and I'm just stumped. The last time I did any shell scripting was 8 years ago on a Unix box, and it was never my strong suit. I'm on a Mac running Leopard now. Here's my dilemma - hopefully someone can point me in the right direction.
I'm... (10 Replies)
Discussion started by: Daniel M. Clark
10 Replies
4. Shell Programming and Scripting
total=0
seq 1 5 | while read i ; do
total=$(($total+$i))
echo $total
done
echo $totalThis outputs:
1
3
6
10
15
0whereas I am expecting:
1
3
6
10
15
15My bash version: (4 Replies)
Discussion started by: meharo
4 Replies
5. UNIX for Dummies Questions & Answers
I need to sort through a volume that contains video files by access time and delete files that have not been accessed over x days. I have to use the access time as video files are originals that do not get modified, just read
Testing commands on a local test folder...
$ date
Wed Sep 28... (10 Replies)
Discussion started by: canon273
10 Replies
6. Shell Programming and Scripting
I was trying to write a simple script which will read a text file and count the number of vowels in the file. My code is given below -
#!/bin/bash
file=$1
v=0
if
then
echo "$0 filename"
exit 1
fi
if
then
echo "$file not a file"
exit 2
fi
while read -n... (14 Replies)
Discussion started by: linux_learner
14 Replies
7. Shell Programming and Scripting
Hi,
I have prepared a script and trying to execute it but not getting expected output. Could you please help and advise what is going wrong.
"If else" part in below script is not working basically.
I am running it on HP-UX.
for i in slpd puma sfmdb
do
echo "******\t$i\t*******"
echo... (10 Replies)
Discussion started by: sv0081493
10 Replies
8. UNIX for Advanced & Expert Users
I ran into the following and still do not understand entirely the rationale behind this. If someone could explain why things are as they are I'd be thankful.
The following was tested on AIX 7.1 with ksh88, but i suspect that to be ubiquitous. In an installation routine i had to create a set of... (6 Replies)
Discussion started by: bakunin
6 Replies
9. Shell Programming and Scripting
Hi All,
i'm getting this error,
can somebody check?
file name is like this
951957039339019_560119_000523_2w47_3060_0038_6002.log
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"
IFS="_" read -r -a array... (2 Replies)
Discussion started by: charli1
2 Replies
10. Shell Programming and Scripting
Following one line of awk code removes first 3 characters from each line but when I run the same code on another linux platform it doesn't work and only prints blank lines for each record. Can anyone please explain why this doesn't work? (31 Replies)
Discussion started by: later_troy
31 Replies
LEARN ABOUT DEBIAN
envstore
ENVSTORE(1) BSD General Commands Manual ENVSTORE(1)
NAME
envstore -- save and restore environment variables
SYNOPSIS
envstore command [args ...]
DESCRIPTION
envstore can save and restore environment variables, thus transferring them between different shells.
command must be one of
clear
Forget all stored variables
eval
Produce shell code for evaluation, restoring all saved variables
list
List saved variables in better readable format
save variable [value]
Save variable either with its current shell value or with value
rm variable
Remove variable from store
Note: Only the first character of command is checked, so envstore e instead of envstore eval, envstore c for envstore clear, etc., are also
valid.
ENVIRONMENT
ENVSTORE_FILE The file in which the environment parameters are stored, /tmp/envstore-EUID by default,
LIMITATIONS
Variable names or values must not contain null bytes or newlines.
Due to limitations imposed by most shells, it is not possible to save parameters containing more than one consecutive whitespace. envstore
will save and display them correctly, but unless you do IFS trickery, your shell will not be able to load them.
The current maximum length (in bytes) is 255 bytes for the variable name and 1023 bytes for its content.
AUTHOR
envstore was written by Daniel Friesel <derf@derf.homelinux.org>.
Original idea and script by Maximilian Gass <mxey@ghosthacking.net>.
SEE ALSO
envify(1)
BSD
December 1, 2009 BSD