Unable to change path in a bash script

Hello friends,
I am trying to change path inside a bash script. What I am doing is
the following.

cd /tmp; find [A-Z] -type f -or -type l | grep wizkid

It gives me the following error:-
cd: /tmp;: No such file or directory

But when I execute the above command directly from shell, I get the
results. I dont know what is happening.

Kindly tell me where am I going wrong and oblige.

Thanks friends for visiting this thread.

Yours truly,
Wizard.
vivek.j.joshi [ So, 18 November 2007 14:07 ] [ ID #1873427 ]

Re: Unable to change path in a bash script

wizard scrisse:

> ...
> It gives me the following error:-
> cd: /tmp;: No such file or directory
> ...

Try:

cd /tmp ;
mallin.shetland [ So, 18 November 2007 14:27 ] [ ID #1873429 ]

Re: Unable to change path in a bash script

On Nov 18, 6:27 pm, "mallin.shetland" <mallin.shetl... [at] aol.com> wrote:
> wizard scrisse:
>
> > ...
> > It gives me the following error:-
> > cd: /tmp;: No such file or directory
> > ...
>
> Try:
>
> cd /tmp ;

It is already as
cd /tmp

It works fine on a command line if I do it, but fails inside the
script. I can't understand why.

Also, I tried the following command in a bash script:-

cmdOutput=`find /tmp -type f -or -type l | grep wizkid`
echo $cmdOutput

It gives me the following error:-

/usr/bin/find: paths must precede expression
Usage: /usr/bin/find [path...] [expression]

whereas, this runs fine on the command line.
vivek.j.joshi [ So, 18 November 2007 14:39 ] [ ID #1873430 ]

Re: Unable to change path in a bash script

wizard wrote:
> Hello friends,
> I am trying to change path inside a bash script. What I am doing is
> the following.
>
> cd /tmp; find [A-Z] -type f -or -type l | grep wizkid
>
> It gives me the following error:-
> cd: /tmp;: No such file or directory

Is this a DOS file with CR (^M) before the line terminator FF?
If so get rid of that.

Janis

>
> But when I execute the above command directly from shell, I get the
> results. I dont know what is happening.
>
> Kindly tell me where am I going wrong and oblige.
>
> Thanks friends for visiting this thread.
>
> Yours truly,
> Wizard.
Janis Papanagnou [ So, 18 November 2007 15:38 ] [ ID #1873435 ]

Re: Unable to change path in a bash script

wizard scrisse:

> ...
> It gives me the following error:-
>
> /usr/bin/find: paths must precede expression
> Usage: /usr/bin/find [path...] [expression]
>
> whereas, this runs fine on the command line.


Try running script whit xtrace on (eg: bash -x ./script
or #! /bin/bash -x) and doing some debug. You can put in
your script somethink as:

ls -l /
ls -l /tmp
pwd
mallin.shetland [ So, 18 November 2007 15:59 ] [ ID #1873438 ]

Re: Unable to change path in a bash script

"Janis Papanagnou" <Janis_Papanagnou [at] hotmail.com> schrieb im Newsbeitrag
news:fhpipg$j4r$1 [at] online.de...
> wizard wrote:
>> Hello friends,
>> I am trying to change path inside a bash script. What I am doing is
>> the following.
>>
>> cd /tmp; find [A-Z] -type f -or -type l | grep wizkid
>>
>> It gives me the following error:-
>> cd: /tmp;: No such file or directory
>
> Is this a DOS file with CR (^M) before the line terminator FF?
LF, not FF

Bye, Jojo
Joachim Schmitz [ So, 18 November 2007 16:10 ] [ ID #1873440 ]

Re: Unable to change path in a bash script

Joachim Schmitz wrote:
> "Janis Papanagnou" <Janis_Papanagnou [at] hotmail.com> schrieb im Newsbeitrag
> news:fhpipg$j4r$1 [at] online.de...
>
>>wizard wrote:
>>
>>>Hello friends,
>>> I am trying to change path inside a bash script. What I am doing is
>>>the following.
>>>
>>>cd /tmp; find [A-Z] -type f -or -type l | grep wizkid
>>>
>>>It gives me the following error:-
>>>cd: /tmp;: No such file or directory
>>
>>Is this a DOS file with CR (^M) before the line terminator FF?
>
> LF, not FF

Sure. Typo. Thanks for catching it.

>
> Bye, Jojo
>
>
Janis Papanagnou [ So, 18 November 2007 19:28 ] [ ID #1873442 ]

Re: Unable to change path in a bash script

wizard <vivek.j.joshi [at] gmail.com> writes:

> cd: /tmp;: No such file or directory

try
ls -ldg /tmp

and tell us what it says. It could be a symbolic link to a directory
that you don't have access to, or a remotely mounted file system.
And in a shell window, try
cd /tmp;df .
cd /; df .

That will tell you the disk partitions for "/" and "/tmp".
I want to see if they are different.

cd /;df .

?
Maxwell Lol [ Mo, 19 November 2007 12:38 ] [ ID #1873837 ]
Linux » comp.unix.shell » Unable to change path in a bash script

Vorheriges Thema: merge two files
Nächstes Thema: Storing result in a variable - newbie question