Page 1 of 1

[SOLVED] scripts syntax questions

Posted: 30 Oct 2015, 10:19
by aus9
Hi

Looking into the /var/log/scripts I noticed most seem to use a formula that looks like this
( cd usr/lib64 ; <command> )
where command is something like linking, removing etc.

I am pretty sure, we must be at / to do this as there is no prefix / as in /usr/lib64

question 1
Can I use this command and get away with it?

Code: Select all

( cd usr/lib64 ;  rm -rf file1 file2
if [ -f file3 ] ; then rm -rf file3 fi )
Or is there some rule, that ( x ) must be all on one line?

question 2
If not, is this acceptable

Code: Select all

cd /usr/lib64 
rm -rf file1 file2
if [ -f file3 ] ; then rm -rf file3 fi
cd /
I am not a great coder so if I have missed something or you have better suggestions please feel free to enlighten me.
I want to get something right before attempting to post something for a new module.

Thanks for reading

Re: scripts syntax questions

Posted: 30 Oct 2015, 12:15
by Bogomips
aus9 wrote: question 1
Can I use this command and get away with it?

Code: Select all

( cd usr/lib64 ;  rm -rf file1 file2
if [ -f file3 ] ; then rm -rf file3 fi )
Or is there some rule, that ( x ) must be all on one line?
Suck it and see. :) Try it out on a harmless directory:

Code: Select all

tst() {
( cd usr/lib64 ;  rm -rf file1 file2
if [ -f file3 ] ; then rm -rf file3 fi )
}
tst
Got as far as:

Code: Select all

guest@porteus:~$ tst() {
> ( cd usr/lib64 ;  rm -rf file1 file2
> if [ -f file3 ] ; then rm -rf file3 fi )
bash: syntax error near unexpected token `)'
guest@porteus:~$ }
Corrected syntax:

Code: Select all

guest@porteus:~$ tst() {
> ( cd usr/lib64 ;  rm -rf file1 file2
> if [ -f file3 ] ; then rm -rf file3; fi )
> }
guest@porteus:~$ 

Re: scripts syntax questions

Posted: 31 Oct 2015, 13:06
by aus9
OK got something to work which is good,

Code: Select all

( cd usr/lib64
 mv file1.so* ../../lib64
 mv file2.so* ../../lib64
)
I have a script that replaced file1 +2 with real filenames this is just to show example

Re: scripts syntax questions

Posted: 31 Oct 2015, 15:40
by Bogomips
@aus9 Solved?

Re: [SOLVED] scripts syntax questions

Posted: 01 Nov 2015, 00:08
by aus9
good enough for now, solved