My variable cannot be passed through into my path

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My variable cannot be passed through into my path
# 1  
Old 08-26-2009
My variable cannot be passed through into my path

Can you please help. I am scripting in sh and I am trying to simply copy one directory to another but for some reason my variables are not recognised?

HTML Code:
echo "The latest version of the program is being found......."
cd $SOFTWARE/src/$progname
version=`ls $SOFTWARE/src/$progname | grep 'v00*'  | tail -1`
echo "Latest version for $progname is $version"
#Copy over the latest version of the program
cp -r $SOFTWARE/src/$progname/$version $SOFTWARE/devl/$progname
The problem is to do with the $version variable it seems because when I subsitute $version with a directory name that is hard coded it works BUT when you simply echo $version it also looks correct. Do I need to convert it to a different format or something?

# 2  
Old 08-26-2009

grep 'v00*' ???
# 3  
Old 08-26-2009
Assuming u meant the extra space, just deleted this but still the $version is not recognised since the cp command does nothing?
# 4  
Old 08-26-2009
I think cabrao meant that you didn't need the *. Besides, with your grep in single quotes the shell would not expand it in any way so it would look for filenames literally including v00*

At the very least in a regular expression you would need .* (without single quotes)

A * in a regular expression matches 0 or more of the last expression (in your case the character 0), whereas . means match any character and .* matches 0 or more of any character.

You should also change your ls to "ls -1".

version=$(ls -1 $SOFTWARE/src/$progname | grep v00  | tail -1)

I don't know the names of the files in your $program directory, but:
version=$(ls -1 $SOFTWARE/src/$progname/*v00* | tail -1)

should also do the same thing.

Don't confuse the * in how the shell expands filenames with * in a regular expression - they're not the same thing.

Last edited by Scott; 08-26-2009 at 02:47 PM..
# 5  
Old 08-27-2009
okay, these alternatives still work but i am facec with the same problem when trying to do the copy, it seems to find the latest directory or version e.g. v003 but it does not copy the directory to the target directory?

if i hard code v003 in the scrpt instead it works though???
# 6  
Old 08-27-2009
post the error lines if you could
# 7  
Old 08-27-2009
don't get any I'm affraid, i only realise it hasn't copied the directory when looking into the target one and its empty. to confirm the source and target are correct I have echoed these pathnames and they appear correct in the terminal and when I do the same command cp -r source target on the command line it works? by the way I'm on the linux too
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 not being passed

In the bash below the variable date displays in the echo. However when I use it in the for loop it does not. Basically, the user inputs a date then that date is converted to the desired format of (month-day-year, no leading 0). That input is used in the for loop to return every file that matches... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Variable not passed to the sed command

Hello, I am writing a script which is not giving the desired result. When I check the content of the '', it shows following with missing Index in this command sed -i "s/L1ITMBLT.root/L1ITMBLT_"".root/g" of . Any help? ... (13 Replies)
Discussion started by: emily
13 Replies

3. Shell Programming and Scripting

Variable passed as argument

I have a script. #!/bin/sh cur_$1_modify_time=Hello echo "cur_$1_modify_time" When I run like sh /root/script1 jj I expect value "Hello" being assigned to variable "cur_jj_modify_time" and output being "Hello" ie echoing $cur_jj_modify_time But the output comes as # sh... (3 Replies)
Discussion started by: anil510
3 Replies

4. Shell Programming and Scripting

In the sh file variable is not being passed on.

I am having difficulties with the fllowing script: !/bin/sh voicemaildir=/var/spool/asterisk/voicemail/$1/$2/INBOX/ echo `date` ':' $voicemaildir >> /var/log/voicemail-notify.log for audiofile in `ls $voicemaildir/*.wav`; do transcriptfile=${audiofile/wav/transcript} ... (4 Replies)
Discussion started by: ghurty
4 Replies

5. Shell Programming and Scripting

[SSH] Accessing remote directory with user-passed path

Hi everybody, Currently, I have a script which access a remote computer via SSH, go to a folder already defined in the code and then executes a program in it, just like that: ssh user@host << EOI cd path ./file EOI It executes fine, but now I want to pass an argument in the command... (2 Replies)
Discussion started by: lgb3
2 Replies

6. UNIX for Advanced & Expert Users

Value of variable not getting passed in child script

Hi, I am facing a challenge in fixing an issue in my installation scripts.Here is a situation: There are 3 files which are invoked at a below given order: Installer.ksh----->Installer.xml(Ant script)------->common.ksh I am outputting a message from common.ksh at a terminal, after that trying to... (3 Replies)
Discussion started by: baig_1988
3 Replies

7. Shell Programming and Scripting

how to find the path of a file when it is passed as ....filename(parameter) to script

hi unix guru's..................:confused: question is posted in the #3 permalink shown below. (3 Replies)
Discussion started by: yahoo!
3 Replies

8. UNIX for Dummies Questions & Answers

Assigning a Variable all the Parameters passed

Hi, I have a unix script which can accept n number of parameters . I can get the parameter count using the following command and assign it to a variable file_count=$# Is there a similar command through which i can assign a variable all the values that i have passed as a parameter ... (2 Replies)
Discussion started by: samit_9999
2 Replies

9. UNIX for Dummies Questions & Answers

variable passed to awk

Does anybody know how to print a variable passed to awk command? awk -F"|" 'BEGIN {print $job,"\n","Question \n"} {print $1,$2$4," ",$3}' "job=$job1" file1 I am trying to pass job the variable job1. the output is blank. ?? (3 Replies)
Discussion started by: whatisthis
3 Replies

10. UNIX for Dummies Questions & Answers

variable passed to awk

Anybody know what's wrong with this syntax? awk -v job="$job" 'BEGIN { FS="|"} {print $1,$2," ",$4," ",$3\n,$5,"\n"}' list It's keeping give me this message: awk: syntax error near line 1 awk: bailing out near line 1 It seems awk has problem with my BEGIN command. Any... (8 Replies)
Discussion started by: whatisthis
8 Replies
Login or Register to Ask a Question