944,135 Members | Top Members by Rank

Ad:
Dec 12th, 2006
0

Using the 'mv' command with paremeters in a script

Expand Post »
Hello everyone. I'm a newbie in shell scripts. I'm trying to write a simple script that will archive a file from one directory to another directory I'm using sqlplus to generate the correct file name. The problem is when I try to use the paremeter from sqlplus it adds a space in front of it.

here is what I have:

#!/usr/bin/sh
directory=/u01/prodappl/orscgl/11.5.0/bin/
directoryNew=/u01/prodappl/orscgl/11.5.0/bin/archive/

file_name=`sqlplus -s apps/apps<<EOQ
set heading off feedback off verify off
SELECT TRIM('GLISPO'||TO_CHAR(sysdate, 'YYYYMMDD')||'.dat') FROM Dual;
exit;
EOQ
`
test=${file_name}
echo $file_name
echo $directory$file_name
echo $directoryNew$file_name
echo ${directoryNew}${test}
echo $test


I've played around trying several different ways of using ``, '', "", and {} and cannot get it to work. Here is the output I get from this.

GLISPO20061212.dat
/u01/prodappl/orscgl/11.5.0/bin/ GLISPO20061212.dat
/u01/prodappl/orscgl/11.5.0/bin/archive/ GLISPO20061212.dat
/u01/prodappl/orscgl/11.5.0/bin/archive/ GLISPO20061212.dat
GLISPO20061212.dat

Notice the spaces between the directory and the filename. This will not work with the mv command.

Thanks for the help.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rchadhaney is offline Offline
3 posts
since Dec 2006
Dec 13th, 2006
0

Re: Using the 'mv' command with paremeters in a script

Shell Scripting Syntax (Toggle Plain Text)
  1. file_name=`echo "$file_name" | sed 's/ //g'`

That removes any spaces in the file_name variable
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004
Dec 14th, 2006
0

Re: Using the 'mv' command with paremeters in a script

Shell Scripting Syntax (Toggle Plain Text)
  1. file_name=`echo "$file_name" | sed 's/ //g'`

That removes any spaces in the file_name variable
Hey thanks for your suggestion. I tried it and it didn't make any difference. I don't think the issue is with the parameter having a space.


#!/usr/bin/sh
directory=/u01/prodappl/orscgl/11.5.0/bin/
directoryNew=/u01/prodappl/orscgl/11.5.0/bin/archive/
file_name=`sqlplus -s apps/apps<<EOQ
set heading off feedback off verify off
SELECT TRIM('GLISPO'||TO_CHAR(sysdate, 'YYYYMMDD')||'.dat') FROM Dual;
exit;
EOQ
`
file_name=`echo "$file_name" | sed 's/ //g'`
test=${file_name}
echo $file_name
echo $directory$file_name
echo $directoryNew$file_name
echo ${directoryNew}${test}
echo $test

and this is what i get:


GLISPO20061214.dat
/u01/prodappl/orscgl/11.5.0/bin/ GLISPO20061214.dat
/u01/prodappl/orscgl/11.5.0/bin/archive/ GLISPO20061214.dat
/u01/prodappl/orscgl/11.5.0/bin/archive/ GLISPO20061214.dat
GLISPO20061214.dat

As you can see the two times I display just the variable there is no space in front of it.. Just when I try to add it to the other varaiable...

Thanks,

Chad.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rchadhaney is offline Offline
3 posts
since Dec 2006
Dec 16th, 2006
0

Re: Using the 'mv' command with paremeters in a script

Why not just format the name as follows:

file_name="GLISPO`date +%Y%m%d`.dat"
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Dec 18th, 2006
0

Re: Using the 'mv' command with paremeters in a script

That's what someone in house told me Thursday. I tried it and it works great. Thanks for your help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rchadhaney is offline Offline
3 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: shell script to get the pid of processes running from prvioues day
Next Thread in Shell Scripting Forum Timeline: databse connection problem in shell script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC