create script

i want to create a script that will aid in automating bash commands, such as making directories, changing permissions, moving files, etc...  

How do I do this?  I am under the impression I need to make an executable file that contains these commands, but what else needs to be done?  Is there some special syntax in the file or something else?  Any links, refrences, hints?
tecumsehjoeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wesly_chenCommented:
Hi,

  First,
# vi auto.sh
---- auto.sh -----

#!/bin/bash

mkdir -p <directory>
chmod < permission> <directory>
mv <source path> <target path>
....
-------------------
   Second,
# chmod +x auto.sh

Then you can run that script
# ./auto.sh   <enter>

Wesly
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LuxanaCommented:
HI,

to create bash script you need to :

1)
create file
touch script.sh
2)
edit file
vi script.sh
first byte of file has to contain interpreter:
#!/bin/bash
http://www.freeos.com/guides/lsst/
3)
make file executable
chmod +x script.sh
4)
run script
./script.sh
-----------------------



------------------------------
Sometimes you do not really have to use script you can use just command. For example chanage permitions for all *txt files to rwxrwxrwx in your home directory u can use command:

find /home/yourname -iname \*.txt -exec chmod 777 {} \;

0
owensleftfootCommented:
I would use aliases for this rather that individual scripts. Edit .bashrc in your home directory and add any aliases you like. They wont  work until you open a new shell or run source .bashrc. A couple of examples that I use -
alias xe="chmod +x"
alias log="cd /var/log"
alias mes="less /var/log/messages"
alias erc ="vi ~/.bashrc;source ~/.bashrc"
xe myfile will make myfile executable. log will change to the /var/log directory etc. You can alias several comands by putting a ; between them. I would only use scripts for more complex tasks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.