Two questions

Two questions

am 11.12.2005 01:19:08 von Marg

Hi,

=46ollowing my previous question ("Subject: cutting"), how can i:

1) Detect if the file filname being stripped is missing in the
filesystem, and accordingly, abort the script with an error;

2) How can i change directories inside a bash script ("cd" doesn't work=
s).

Any help would be apreciated.

Warm Regards,
M=E1rio Gamito
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Two questions

am 11.12.2005 01:56:57 von foo

What do you mean `cd` is not working?

#This is scr.sh
#!/bin/bash
for i in `find /root -name "$1"` ; do echo "it's=20
here $i" ; do_whatever_to $i ; done
cd /root ; pwd ; ls -l tcp*.tar.gz
cd /home ; pwd ; ls -l ps.tar
cd ~

it will give you this:

root@ludmila:~# . scr php*.tar.gz
it's here /root/phpshell-latest.tar.gz
/root
-rw-r--r-- 1 root root 655088 2005-04-07 03:47 tcpdump-3.9.1-096.tar.=
gz
-rw-r--r-- 1 root root 3773308 2004-11-05 01:09 tcptrace-6.6.7.tar.gz
/home
-rw-r--r-- 1 root root 163840 2005-04-13 22:44 ps.tar



--Adrian.

At 02:19 AM 12/11/2005, MARG wrote:
>Hi,
>
>Following my previous question ("Subject: cutting"), how can i:
>
>1) Detect if the file filname being stripped is missing in the
>filesystem, and accordingly, abort the script with an error;
>
>2) How can i change directories inside a bash script ("cd" doesn't wor=
ks).
>
>Any help would be apreciated.
>
>Warm Regards,
>M=E1rio Gamito
>-
>To unsubscribe from this list: send the line "unsubscribe linux-admin"=
in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html


-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Two questions

am 11.12.2005 09:55:47 von Glynn Clements

MARG wrote:

> Following my previous question ("Subject: cutting"), how can i:
>
> 1) Detect if the file filname being stripped is missing in the
> filesystem, and accordingly, abort the script with an error;

if [ ! -f "$file" ] ; then
echo "file '$file' not found" >&2
exit 1
fi

> 2) How can i change directories inside a bash script ("cd" doesn't works).

A process can only change its own working directory; you cannot change
the working directory of another process. E.g. a script cannot change
the working directory of its parent (the process from which the script
was run).

--
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html