[SOLVED] scripts syntax questions

Post here if you are a new Porteus member and you're looking for some help.
Post Reply
aus9

[SOLVED] scripts syntax questions

Post#1 by aus9 » 30 Oct 2015, 10:19

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
Last edited by aus9 on 01 Nov 2015, 00:07, edited 1 time in total.

Bogomips
Full of knowledge
Full of knowledge
Posts: 2560
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: scripts syntax questions

Post#2 by Bogomips » 30 Oct 2015, 12:15

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:~$ 
Last edited by Bogomips on 30 Oct 2015, 12:58, edited 3 times in total.
Reason: For instance
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

aus9

Re: scripts syntax questions

Post#3 by aus9 » 31 Oct 2015, 13:06

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

Bogomips
Full of knowledge
Full of knowledge
Posts: 2560
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: scripts syntax questions

Post#4 by Bogomips » 31 Oct 2015, 15:40

@aus9 Solved?
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

aus9

Re: [SOLVED] scripts syntax questions

Post#5 by aus9 » 01 Nov 2015, 00:08

good enough for now, solved

Post Reply