unable to use command line to cd or ls


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers unable to use command line to cd or ls
# 1  
Old 03-07-2008
unable to use command line to cd or ls

Hi:

I have a script with the next command line

>set a=(grep -w "something" textfile.txt | grep -w "anotherthing" | cut -c1-11)

In the file textfile.txt there are some file names and their paths so when I use this command line it returns a path, for example /directory, and stores in a.

when I try
>cd $a
it comes with the error "Too many arguments", I know that $a is /directory, but if i do >echo $a it returns the command line, this is why i cant use cd $a.

is there a way to actually store the file path into the variable and not the command line. So when ever do >set | grep a it will acutally display
a /directory

I really need you help.

Thank you
# 2  
Old 03-08-2008
Use:
echo "$a"
to debug the problem.
# 3  
Old 03-08-2008
Sorry i probably dont explained my self, what i am trying to do is
>cd $a
or
>ls $a

but none of this work and i have tried >cd echo $a, and >$a | cd
both for cd and ls... i know that when i execute just $a i get the path that was copied from the textfile.txt, but when i see what the variable contain it contains the command line, eval grep -w "something" textfile.txt | grep -w "anotherthing" | cut -c1-11.

please tell me how to use either cd or ls with the value i get from the execution of the command line (grep -w "something" textfile.txt | grep -w "anotherthing" | cut -c1-11)

Thank you
# 4  
Old 03-08-2008
I think you're probably using csh with that syntax and I don't really know csh real well. Also I'm not sure what you're trying to do. But to get the results of a command line into a variable, try using backquotes. I just tried this with csh...
Code:
%echo 1+2 | bc
3
%set a=`echo 1+2 | bc`
%echo $a
3
%

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to check if my command succeeded

Hi, Is there a way to check if the openssl part of the below execution returns non zero without freezing the flow of the script ? var1=$(echo | openssl s_client -connect $url 2>/dev/null | openssl x509 -noout -issuer -subject -dates) echo $? Output: 0 while i was expecting the... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

Unable to set end of line in mail command

Hi , Am trying to send mail using the mail command, but the mail command is working but its not sending automatically after pressing .(dot) in the command prompt it sends . How to achieve that. Also it showing the below line after pressing the dot . /home/abc1/dead.letter... Saved message in... (5 Replies)
Discussion started by: rogerben
5 Replies

4. AIX

Unable to execute snap command

Hi Friends, I am not able to execute snap -a command in AIX 6 system. Could you please let me know how to make work this command and Path to be set. Thanks in Advance Siva. (4 Replies)
Discussion started by: sivakumarl
4 Replies

5. UNIX for Dummies Questions & Answers

tar unable to use command

Hello all... i am unable to use tar commands on my intel machine in solaris 10 by tying this "tar cvf /dev/rmt/mydata.tar/mydata" and created mydata directory, msg is "No:Missing Files" Please advise (5 Replies)
Discussion started by: VijaySolaris
5 Replies

6. Shell Programming and Scripting

unable to use new line in sed search pattern.

hi , my lilo.conf is as shown below : prompt default=Primary read-only image=/boot/bzImage label=Primary root=/dev/md0 append="reboot=t md=0 ip=off panic=5 quiet console=ttyS0,115200n81" read-only image=/boot/bzImage label=Recover root=/dev/sda3 ... (7 Replies)
Discussion started by: success
7 Replies

7. UNIX for Dummies Questions & Answers

[SOLVED] Command line mail taking too long to send; unable to qualify my own domain name

Hello, I'm having a problem with my mail. When I send mail, it takes a long time for the send to complete. In the below, datestamp is just a simple script to put in a no-white-space date/time stamp. $ datestamp ; mail woodnt; datestamp 02-05-10@193844 Subject: test timer Cc: ... (0 Replies)
Discussion started by: Narnie
0 Replies

8. Shell Programming and Scripting

Unable to display correctly the contents of a file without a line feed

I am using AIX and ksh. I need to display the contents of a file that has a pid (process id). Because the file is open, it doesn't have the line feed or new line, so for some reason if I do this: `cat $pid` , where $pid is the name of the fully qualified file, it displays test3.sh: 426110:... (1 Reply)
Discussion started by: Gato
1 Replies

9. BSD

Unable to use 'su' command on FreeBSD6.2

Hi, I'm unable to do 'su' on my FreeBSD6.2 machine, I can remote ssh login as root but 'su' simply doesn't work at all. The message I get says that "The Operation Not Permitted". Requesting any help. Thanks in advance. (3 Replies)
Discussion started by: Praveen_218
3 Replies

10. UNIX for Dummies Questions & Answers

unable to display the souce line in gdb

Hi All, I am unable to display the code in gdb. When i put list command i dont get any line. I mean i am unable to display the source line in gdb. Can any body help me. Thanks & Regards Gauri (4 Replies)
Discussion started by: gauri
4 Replies
Login or Register to Ask a Question