Command to run multiple commands from a file.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command to run multiple commands from a file.
# 1  
Old 02-13-2009
Network Command to run multiple commands from a file.

I need a command, which could run mutliple commands from a file.
Let's say, I have
mv fileA1 fileB1
mv fileA2 fileB2
.....
mv fileA20 fileB20
I put these commands in a file, then I need a command to run the file as a whole so that I don't need to type 20 times...
Anyone tell me how to do this?? thanks!!

Last edited by kaixinsjtu; 02-13-2009 at 04:05 AM..
# 2  
Old 02-13-2009
Quote:
Originally Posted by kaixinsjtu
I need a command, which could run mutliple commands from a file.
Let's say, I have
mv fileA1 fileB1
mv fileA2 fileB2
.....
mv fileA20 fileB20
I put these commands in a file, then I need a command to run the file as a whole so that I don't need to type 20 times...
Anyone tell me how to do this?? thanks!!
Fill in the numbers as required.

Code:
for filenum in 1 2 3
do
  mv fileA${filenum} fileB${filenum}
done

# 3  
Old 02-13-2009
what if their files names are all different, like x, y,z but I need to use the same command 'mv' for 20 times on 20 different files?? thanks!!

Quote:
Originally Posted by vino
Fill in the numbers as required.

Code:
for filenum in 1 2 3
do
  mv fileA${filenum} fileB${filenum}
done

# 4  
Old 02-13-2009
Quote:
Originally Posted by kaixinsjtu
what if their files names are all different, like x, y,z but I need to use the same command 'mv' for 20 times on 20 different files?? thanks!!
Is there some pattern between the source and destination file names ? If no, then it becomes hard to automate it.
# 5  
Old 02-13-2009
hi,
I think you have put all the 20 mv in a single file and you want to execute the file. Am i clear??
if that so then try this
for example if your file is move.txt
chmod 777 move.txt
./move.txt
I think this must work
# 6  
Old 02-14-2009
Yes, you are absolutely right. Thanks!
i just wonder, what does 777 means here??

Quote:
Originally Posted by janani_kalyan
hi,
I think you have put all the 20 mv in a single file and you want to execute the file. Am i clear??
if that so then try this
for example if your file is move.txt
chmod 777 move.txt
./move.txt
I think this must work
# 7  
Old 02-15-2009
777 means 'full permissions'. anyone has permission to read, write, or execute the file.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python script to run multiple command and append data in output csv file

Experts, I am writing a script and able to write only small piece of code and not able to collect logic to complete this task. In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file Now have to... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Run multiple commands in ssh

Hi All, I have the below requirement. I want to copy the local file to remote after that i need to run the local script on a remote machine.When i use two ssh commnds i can achieve this. But i want to achieve this using one ssh command. Below command to copy the local file to remote ssh -q... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

3. Shell Programming and Scripting

[Solved] Run multiple commands in invoked program

Hi, I have coded a program in Haskell using the compiler Hugs and the program requires multiple commands (with parameters) to be entered into it, it then outputs the result of its execution. I need to test a lot of different options (i.e. the parameters) so it would be obvious to automate the... (0 Replies)
Discussion started by: tz742
0 Replies

4. UNIX for Dummies Questions & Answers

Run multiple commands

Hi All, Is it possible to run second/multiple commands at a time in script before the completion/return of first command? Pls reply. (5 Replies)
Discussion started by: cns1710
5 Replies

5. SuSE

Allow multiple users to run several root commands

I am using SUSE Linux Enterprise Server 10 SP2 (i586) and I had earlier ammended my sudoers file to allow users to become root user with "sudo su - " command Now I am trying to add multiple users to the sudoers file to run several commands such as restarting the server, restarting the nagios... (9 Replies)
Discussion started by: hedkandi
9 Replies

6. Shell Programming and Scripting

Script to run command against multiple specific value in one file

Hi all, I am trying to create a shell script from solaris 10 server to run a command into multiple specific value in one file. The command is related to Oracle/Sun JES2005Q4 directory server. #this is the command, #from path /jes/ds/slapd-rldap1 ./ns-inactivate.pl -h mldap1 -p 389 -D... (12 Replies)
Discussion started by: Mr_47
12 Replies

7. UNIX for Dummies Questions & Answers

How to run multiple piped commands in a find -exec statement?

I can't get this to work. Running a single command works fine: find . -name "*.dat" -exec wc -l '{}' \; gives me the file name and number of lines in each .dat file in the directory. But what if I want to pipe commands, e.g. to grep something and get the number of lines with that pattern... (3 Replies)
Discussion started by: DJR
3 Replies

8. Shell Programming and Scripting

Run multiple commands in $() without opening a new shell

The code below works, but takes too many lines and looks awkward: db2 "export to $filename of del select * from $table with ur"|tee -a $LOGFILE|awk '/Number of rows exported:/ {print $5}' > numrows.tmp numrows=$(cat numrows.tmp) rm numrows.tmp When I try the... (2 Replies)
Discussion started by: akar_naveen
2 Replies

9. UNIX for Dummies Questions & Answers

How to run multiple command in single command?

Dear Unix Guru, I have several directories as below /home/user/ dir1 dir2 dir3 Each directory has different size. I want to print each directory size (Solaris command du -hs .) Can you please guide me how to achieve this? Thanks Bala (2 Replies)
Discussion started by: baluchen
2 Replies

10. UNIX for Dummies Questions & Answers

Can I use history command to run previous commands?

Hi, I can use history command in unix to view my last 50 commands. But how can I run the previous commands easily? Can history command help? Firebird (2 Replies)
Discussion started by: firebirdonfire
2 Replies
Login or Register to Ask a Question