•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,421 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,629 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 2556 | Replies: 4
![]() |
•
•
Join Date: Dec 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
•
•
Join Date: May 2004
Posts: 177
Reputation:
Rep Power: 5
Solved Threads: 9
file_name=`echo "$file_name" | sed 's/ //g'`
That removes any spaces in the file_name variable
•
•
Join Date: Dec 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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.
Why not just format the name as follows:
file_name="GLISPO`date +%Y%m%d`.dat"
file_name="GLISPO`date +%Y%m%d`.dat"
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Bash Mail script help (Shell Scripting)
- Invoking a shell script (PHP)
- Mail command (Shell Scripting)
- Take input from a file and perform a command (Shell Scripting)
- (Need Help !Urgent) In dump Command (Shell Scripting)
- help with shell script padding files with spaces (Shell Scripting)
- problem in using pppd in shell script (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: shell script to get the pid of processes running from prvioues day
- Next Thread: databse connection problem in shell script



Linear Mode