简体   繁体   English

命令行中的Shell脚本-path和run命令

[英]Shell script -path and run command in one line

I need to execute "n" number of shell script using a master shell script (which have all the command to start other shell script). 我需要使用主shell脚本(具有启动其他shell脚本的所有命令)执行“ n”个shell脚本。 Since all other shell script are located in different location,can't give same path for all and I don't want to repeat "cd" command will be repeating for doing the same. 由于所有其他Shell脚本都位于不同的位置,因此无法为所有人提供相同的路径,并且我也不想重复执行“ cd”命令。

Apart from this, is there any way that i can start my shell script with both run and path given in one line? 除此之外,有什么方法可以在一行中同时给出运行和路径来启动我的shell脚本吗?

eg: 例如:

"run command" "path" (for  file)
"run command" "path" (for  file1)

Kindly can anyone help on this. 对此,任何人都可以提供帮助。

As far as I am able to understand your requirement, it lists down following objectives: 据我能理解您的要求,它列出了以下目标:

  1. You dont want to change your current path in order to execute different scripts at different paths. 您不想更改您的当前路径以便在不同的路径执行不同的脚本。

    Solution: 解:

    a. 一种。 You can directly run your scripts in command line with full absolute path without changing your current path. 您可以使用完整的绝对路径直接在命令行中运行脚本,而无需更改当前路径。

    b. b。 You can use bash commands, pushd and popd to frequently switch between your current path and the other location. 您可以使用bash命令(通过推入和弹出)经常在当前路径和其他位置之间切换。

  2. Starting the shell script with both run and path given in one line. 以一行给出的运行和路径启动外壳脚本。 Solution: 解:

    This can be achieved by use of semi colon between the two commands. 这可以通过在两个命令之间使用半冒号来实现。 For example: Creating a folder in some other location than current directory through 1 line command can be done as: 例如:通过1行命令在当前目录以外的其他位置创建文件夹可以通过以下方式完成:

    cd /home/user ; mkdir testfolder

  3. If the run command uses path as an input argument to run command. 如果运行命令使用路径作为运行命令的输入参数。 Solution: 解:

    This can be achieved by using pushd and popd commands before execution of each command. 这可以通过在执行每个命令之前使用push和popd命令来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM