How to run scripts under Linux‏

翻译 2013年12月04日 23:23:44

How do I run a Linux shell script? How can I run a script in Linux operating system using command line options?

By default shell script will not run. You need to set execute permission for your shell script. To execute or run script type the following command:

chmod +x script-name-here OR   chmod 0755

Next, use the ls command to view permission on the script:
$ ls -l script-name-here
To execute the script, type:
$ ./script-name-here
You can also run a script using any one of the following syntax:
$ /path/to/shell/script/
Run a script called backup.ksh using ksh shell:
$ ksh backup.ksh
Run a script called backup.bash using BASH shell:
$ bash backup.bash


Create a shell script called using a text editor such as vi or gedit:
echo "Hello $USER."
echo "Today is $(date)"
echo "Current working directory : $(pwd)"
Save and close the file. Set the permission:
$ chmod +x
Run the script:
$ ./
If the current directory is in the PATH variable, you can avoid typing the ./ before the It is a good idea to create your own bin directory as follows:
$ mkdir $HOME/bin
Add $HOME/bin to the PATH variable using bash shell export command:
$ export PATH=$PATH:$HOME/bin
$ echo $PATH

Move in $HOME/bin using the mv command, run:
$ mv $HOME/bin
Execute the script:
Sample outputs:
Hello vivek.
Today is Thu Nov 10 17:49:15 IST 2011
Current working directory : /nafiler05/users/v/vivek/bin/demos


How to use "chmod" under linux

This "chmod" command is be used quite a lot. and I cry for understanding and being familiar with thi...

how to compile and run cocos2dx in linux

I believe for android development, linux is much better than windows. Originally development in visu...

How to change the default run level of a RedHat 9.0 or Fedora Core Linux system

During the boot process for Redhat 9.0 and Fedora Core systems the init command opens the /etc/ini...
  • hhcjb
  • hhcjb
  • 2011年12月15日 13:21
  • 315

How to install QEMU under FreeBSD 8.1 as host

QEMU is a processor emulator that relies on dynamic binary translation to achieve a reasonable speed...

How to Post Data and Fetch Remote Pages from PHP Scripts Published: ...
  • maroee
  • maroee
  • 2012年03月04日 15:47
  • 526

HOW-TO:Debug Python Scripts with Eclipse

HOW-TO:DebugPython Scripts with Eclipse From XBMC Jump to: navigation,search Here is amethod yo...
  • lzy_168
  • lzy_168
  • 2011年11月17日 13:52
  • 2038

How to install flash player under ubuntu

  • 2014年04月26日 14:13
  • 216B
  • 下载

Linux 启动顺序 添加开机启动服务 rc?.d rc.local init.d System run levels and init.d scripts

Ubuntu 的 运行级别
  • me10zyl
  • me10zyl
  • 2014年07月27日 10:13
  • 1617

This howto guide shows you’ll how to enable EPEL repository under RHEL/CentOS 6/5 to install additio

This howto guide shows you’ll how to enable EPEL repository under RHEL/CentOS 6/5 to install addit...
您举报文章:How to run scripts under Linux‏