Writing shell scripts and executing

Source: Internet
Author: User

This study: Understanding the shell, how to write shell scripts and execute
The shell is actually a program that interprets the execution of commands,
The so-called shell programming is to use a certain syntax to combine the various basic commands, let the shell program to explain the execution.
If you understand the DOS of Windows, you can understand that, in fact, the shell script file and the. bat batch file are similar.
However, the shell under Linux is much more powerful than Windows DOS, hehe.
For security reasons, create a regular account to learn
]# Useradd Cnetsa
]# passwd Cnetsa
Then use the Cnetsa user to log on to Linux
Bash is just one of the shells, and there are other shells, such as sh, tcsh, ksh, etc.
View the shell currently in use
Echo $SHELL

I'm now using the CentOS 5.5 Linux default is to use the bash shell
Ubuntu10.10 also uses bash, the previous Redhat 9.0 should also be
//=====================================================
How do I write a shell script? Using the Vi/vim editor,
VI my_01.sh
echo "Hello, start learning shell scripting"
Save exit: Wq, to enter Chinese characters, set UTF-8 in putty
But this script does not have permission to execute, we need to add a permission to this file
[Email protected] ~]$./my_01.sh
-bash:./my_01.sh:permission denied
Add an Execute permission to the current user
chmod u+x my_01.sh
Bash my_01.sh
This specifies that the bash shell be used to execute the script
However, we do not generally do this, we generally specify the script file at the beginning of the #!/bin/bash
//=====================================================
About path to set the current path, before modifying it is recommended that you first make a backup
[Email protected] ~]$ my_01.sh
-bash:my_01.sh:command not found
[Email protected] ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/cnetsa/bin
Echo $PATH
Ls/bin
Path= $PATH:.
This is only a temporary modification, once restarted, the re-login is invalid.
To make a permanent change, you need to modify a file
Vi/etc/profile Add the following two lines at the end
Path= $PATH:.
Export PATH
Save exit
Use the source command to have the profile take effect immediately
Source/etc/profile
This video ends here in 88.

Original link: http://bbs.linuxtone.org/thread-8024-1-1.html

Writing shell scripts and executing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.