Stringing Multiple commands together in KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stringing Multiple commands together in KSH
# 1  
Old 07-01-2010
Stringing Multiple commands together in KSH

I am trying to to this
Code:
findCDZfile=`ls -at `find /opt/apps/busobj/bobj/bobje/data/ -name CDZ*.tmp``

and it doesn't seem to like me - is there a special escape character I need to use?
# 2  
Old 07-01-2010
Hi.

I would stop using backquotes and use the $( ... ) notation, which is both easily nested, and readable.

Code:
findCDZfile=$(ls -at $(find /opt/apps/busobj/bobj/bobje/data/ -name CDZ*.tmp))

Otherwise if you escape the inner backquotes with \, it should work.

Code:
findCDZfile=`ls -at \`find /opt/apps/busobj/bobj/bobje/data/ -name CDZ*.tmp\``

# 3  
Old 07-01-2010
Quote:
findCDZfile=`ls -at `find /opt/apps/busobj/bobj/bobje/data/ -name CDZ*.tmp``
IMHO, never store more than one variable in a shell variable. Certainly not a directory listing. Process the pipe file-by-file. Also escape (prefix with \) any characters which you do not wish to be expanded by shell or treated as a unix regular expression. This approach also deals with filenames containing spaces correctly.
For example:

Code:
find /opt/apps/busobj/bobj/bobje/data/ -name CDZ\*\.tmp | \
while read findCDZfile
do
       ls -ald "${findCDZfile}"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ksh with Oracle commands

works fine. echo "Deleting CHOPOne Coreaccess from LAUA..." $ORACLE_HOME/bin/sqlplus username/password@servername << ! delete from usergrpdtl where username='acker'; commit; ! but not working with "if statement" even $TMPDIR/adlogin.log exists and greater than 0. if then ... (9 Replies)
Discussion started by: lawsongeek
9 Replies

2. UNIX for Advanced & Expert Users

Pass Multiple Commands and Open Multiple Xterms via PSS

Hello, I'm attempting to open multiple xterms and run a command as an SAP user via sudo using PSSH. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in to the servers in the file list, and SUDO to the SAP(ADM) user, but it won't do anything else... (11 Replies)
Discussion started by: icemanj
11 Replies

3. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

4. Shell Programming and Scripting

SED sub commands in KSH not working for me

I am using SED to edit a file (called file) the file contains the word "ERROR" and I want to use SED to: 1. Search for text "ERROR" If found, 2. Append new line with text "hoi" I tried: sed 's/ERROR/ a\hoi' file sed 's/ERROR/ a\ hoi' file I get all the time the error sed:... (7 Replies)
Discussion started by: Alex400
7 Replies

5. UNIX for Dummies Questions & Answers

Calling commands with ksh

Hi, I am not able to run below command on linux, it however works on solaris. If anyone knows the reason and a solution for it can you please let me know ? Linux ----- $> ksh 'echo hi' ksh: echo hi: No such file or directory $> which ksh /usr/bin/ksh Solaris ------ $> ksh 'echo... (2 Replies)
Discussion started by: krishnaux
2 Replies

6. Solaris

Help with executing multiple remote commands after multiple hops

Hi SSHers, I have embedded this below code in my shell script.. /usr/bin/ssh -t $USER@$SERVER1 /usr/bin/ssh $USER2@S$SERVER2 echo uptime:`/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5` SSH to both these servers are public-key authenticated, so things run... (13 Replies)
Discussion started by: LinuxUser2008
13 Replies

7. Shell Programming and Scripting

KSH variable containing piped commands

Hi, I am trying to execute a bunch of piped command which are stored in a variable, but only one command executed at a time, and rest of the pipes, commands and their arguments are considered as argument to the very first command. Can you please help me in this? bash-2.05$ cat test.sh... (1 Reply)
Discussion started by: prashant.ladha
1 Replies

8. UNIX for Advanced & Expert Users

Better KSH commands

Are there any documents available for checking the execution time taken by ksh commands? My requirement is to fine tune a set of shell scripts having lot of "echos" and "date"s. Is there a better replacement for the below code?. echo "ABC process started on `date`" some code.. echo... (12 Replies)
Discussion started by: engineer
12 Replies

9. UNIX for Dummies Questions & Answers

ksh substring commands

I am trying to get various portions of strings in my script, but am getting a substitution error. I followed the syntax that was described when I goggled this, but I can't get anything to work. #! /bin/ksh/ hello="adklafk;afak" #hello=${hello:3} hello=${$hello:3} happy="hey" echo... (1 Reply)
Discussion started by: anderssl
1 Replies

10. Shell Programming and Scripting

ksh GUI commands

I have a few scripts that i would like to make into GUI's. Are there scripting commands to make GUI's if so where can i get the list of commands and what they do or if anyone has an example of it. Anything will help, thanks (1 Reply)
Discussion started by: daltonkf
1 Replies
Login or Register to Ask a Question