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 script.sh

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/backup.sh
Run a script called backup.ksh using ksh shell:
$ ksh backup.ksh
Run a script called backup.bash using BASH shell:
$ bash backup.bash

Example

Create a shell script called hello.sh using a text editor such as vi or gedit:
 
#!/bin/bash
echo "Hello $USER."
echo "Today is $(date)"
echo "Current working directory : $(pwd)"
 
Save and close the file. Set the permission:
$ chmod +x hello.sh
Run the script:
$ ./hello.sh
If the current directory is in the PATH variable, you can avoid typing the ./ before the hello.sh. 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 hello.sh in $HOME/bin using the mv command, run:
$ mv hello.sh $HOME/bin
Execute the script:
$ hello.sh
Sample outputs:
Hello vivek.
Today is Thu Nov 10 17:49:15 IST 2011
Current working directory : /nafiler05/users/v/vivek/bin/demos

Tomcat启动失败的解决办法

Tomcat启动失败的解决办法Windox7 在win7上已经安装了JDK1.7并设置好了JAVA_HOME,可偏偏Tomcat在启动过程中找不到。报错信息 The JRE_HOME enviro...
  • bqz728568327
  • bqz728568327
  • 2016年10月06日 11:47
  • 1534

【神经网络与深度学习】Caffe Model Zoo许多训练好的caffemodel

Caffe Model Zoo 许多的研究者和工程师已经创建了Caffe模型,用于不同的任务,使用各种种类的框架和数据。这些模型被学习和应用到许多问题上,从简单的回归到大规模的视觉分类,到Siame...
  • LG1259156776
  • LG1259156776
  • 2016年09月28日 09:23
  • 4294

Ambari集成Hadoop安装

1. 安装准备 1.1. 操作系统 CentOS6.5 1.2. 文件准备 ambari安装有两种方式: 1.在线安装 2.离线安装 官网提供的在线安装的repository地址不正确, 需要修改,...
  • sunbow0
  • sunbow0
  • 2014年12月16日 16:06
  • 8488

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...
  • yongdun_007
  • yongdun_007
  • 2011年01月09日 21:27
  • 997

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
  • 337

how to compile and run cocos2dx in linux

I believe for android development, linux is much better than windows. Originally development in visu...
  • laschweinski
  • laschweinski
  • 2011年09月04日 09:51
  • 4600

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...
  • leoly521
  • leoly521
  • 2011年01月17日 11:58
  • 483

under linux fedora the led and adc sample run on the same time

  • 2013年08月23日 16:56
  • 15KB
  • 下载

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
  • 2079

How to Post Data and Fetch Remote Pages from PHP Scripts

http://phpstarter.net/2008/12/how-to-post-data-and-fetch-remote-pages-from-php-scripts/ Published: ...
  • maroee
  • maroee
  • 2012年03月04日 15:47
  • 565
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to run scripts under Linux‏
举报原因:
原因补充:

(最多只允许输入30个字)