Basic variable expansion not working...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Basic variable expansion not working...
# 1  
Old 04-21-2007
Basic variable expansion not working...

Code:
 #!/usr/bin/bash

if [ $# = 0 ]
then
echo "Not valid arguments entered. Just username should be entered."
else

USER_NAME=$1
FILE_NAME=$USER_NAME.info
UNN=STUDIN\\\\$1
echo $UNN

last STUDIN\\\\$1
last UNN

If I type `last STUDIN\\eip060` it works but if I try to expand it with variable it is not working. Any hints and tips are very appreciated!!!

Evgeni
# 2  
Old 04-21-2007
have you tried using the -x flag to see what is actually getting executed on this line of your script?
# 3  
Old 04-21-2007
+ '[' 1 = 0 ']'
+ USER_NAME=eip060
+ FILE_NAME=eip060.info
+ UNN='STUDIN\\eip060'
+ echo 'STUDIN\\eip060'
STUDIN\\eip060
+ last 'STUDIN\\eip060'

wtmp begins Mon Apr 2 09:14:18 2007
+ last UNN

wtmp begins Mon Apr 2 09:14:18 2007
# 4  
Old 04-21-2007
I do not understand what all that backslash stuff is. But I the last line needs to be:
last $UNN
# 5  
Old 04-21-2007
Quote:
Originally Posted by Perderabo
I do not understand what all that backslash stuff is. But I the last line needs to be:
last $UNN
Ok... the first backslash removes the special meaning of the second backslash.
The real username is STUDIN\eip060.
So when I write `last STUDIN\\eip060` I get list of my loggings but when I do ...

UNN=STUDIN\\\\eip060#what really gets in UNN is STUDIN\\eip060(what i need))
last $UNN (It does not work... I do not get the loggings of STUDIN\\eip060)...
# 6  
Old 04-21-2007
Quote:
Originally Posted by Zammy_bg
+ '[' 1 = 0 ']'
+ USER_NAME=eip060
+ FILE_NAME=eip060.info
+ UNN='STUDIN\\eip060'
+ echo 'STUDIN\\eip060'
STUDIN\\eip060
+ last 'STUDIN\\eip060'

wtmp begins Mon Apr 2 09:14:18 2007
+ last UNN

wtmp begins Mon Apr 2 09:14:18 2007
The output here indicates that you are using twice as many \'s as you should.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash variable expansion

Hello. The file /etc/fstab contains UUID=957c3295-9944-1593-82e2-2b90dede4312 / ext4 noatime,discard,acl,user_xattr 1 1 I fill a variable SOME_LINE=$( cat /etc/fstab | grep \/\..*ext4 | grep noatime,discard )echo $SOME_LINE... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Expansion not working properly

I'm using an Ubuntu machine and expansion is not working properly. What would cause this? Do I need to check for any particular bash packages? $ ipcs -m | grep $USER | awk '{printf "%s ",$2}' $ ipcs -m | grep UNF | awk '{printf "%s ",$2}' 294912 1048577 425986 688131 786436 1245189... (14 Replies)
Discussion started by: cokedude
14 Replies

3. Shell Programming and Scripting

Help required regarding variable expansion in UNIX

Hello, I have one variable coming from one file: abc=$xyz/filename.txt where $xyz is defined in .profile file as say, /usr/dev/src i am passing abc variable to one perl script as input parameter. perl 123.pl -s $abc But inside the perl script execution, the variable $abc is just... (1 Reply)
Discussion started by: vikas_trl
1 Replies

4. Shell Programming and Scripting

Parameter expansion not working for all strings...

I'm trying to write a script that parses my music collection and hard link some filenames that my media player doesn't like to other names. To do this I need to extract the name and remove alla non ASCII characters from that and do a cp -l with the result. Problem is this: 22:16:58 $... (8 Replies)
Discussion started by: refuser
8 Replies

5. UNIX for Dummies Questions & Answers

Can I use a variable with brace expansion?

So, I was bored on the train today, and was thinking of ways to loop through elements of an array. I came up with the following simple script, but it doesn't work as brace expansion doesn't seem to work with variables. Is there something I'm missing, or does the shell just not work like this? ... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

6. Shell Programming and Scripting

delay variable expansion

Hi forum, in my bash script I've many lines executing commands with redirection to log files. ... xyz_cmd 2>&1 > $BASENAME.$LINENO The trailing part of these lines doesn't look nice and I like to put it into a variable. The (not working) idea is something like that ... (3 Replies)
Discussion started by: wolfi089
3 Replies

7. Shell Programming and Scripting

Variable expansion in sed

The objective of the code below is to create sed script to be later executed. However, it bonks because $ARCHIVENAME expands to a directory specification so the forward slashes cause problems. I can think of a few solutions that would involve redesigning the process, but I'm hoping there might be... (4 Replies)
Discussion started by: tiggyboo
4 Replies

8. UNIX for Dummies Questions & Answers

Variable brace expansion

I'm in the habit of using the following type of loop structure: for num in `seq $1 $2` do command doneWhile `seq $1 $2` is not exactly a huge resource hog, I would like to learn a better way. It seems that brace expansion is a good way to go: for num in {3..10}The problem, though, is... (2 Replies)
Discussion started by: treesloth
2 Replies

9. Shell Programming and Scripting

bash - delay expansion of variable

Hello - I have a bash script which does some logging, and I'd like to include the line number of the echo statement that pipes into $LOGGER: MYPID=$$ MYNAME=`basename $0` LOGGER="/usr/bin/logger -t $MYNAME($LINENO) -p daemon.error" ... echo 'this is an entry into the log file' | $LOGGER ... (3 Replies)
Discussion started by: scandora
3 Replies

10. UNIX for Dummies Questions & Answers

ksh on HP-UX -- variable expansion

We have a script that runs in ksh on HP-UX 11.11. It takes three arguments. The last argument can be a filename or wildcard character. For example: script -s hello -t goodbye '*.d*' In a case such as this, I would wrap single quotes around the final argument because I dont want the shell to... (4 Replies)
Discussion started by: dangral
4 Replies
Login or Register to Ask a Question