Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从bash脚本运行shell脚本_Bash_Shell - Fatal编程技术网

如何从bash脚本运行shell脚本

如何从bash脚本运行shell脚本,bash,shell,Bash,Shell,我在运行以下命令时出现错误(在:sh up.sh行上): #!/bin/bash # Install angular components echo "Installing Angular Components..." cd angApp npm install # Install Server components echo "Installing Backend Components..." cd .. cd APIServer # go back to main dir cd ..

我在运行以下命令时出现错误(在:sh up.sh行上):

#!/bin/bash

# Install angular components 
echo "Installing Angular Components..."
cd angApp
npm install

# Install Server components
echo "Installing Backend Components..."
cd ..
cd APIServer

# go back to main dir
cd ..

# ask to see if we should launch server
echo "Do you want to launch the server now? Enter (yes/no)  "
read shouldLaunch

# Launch if requested. Otherwise end build
if [ "$shouldLaunch" == "yes" ]; then
    echo "Great! Launching the servers for you..."
    sh up.sh
else
    echo "No problem..."
    echo "you can launch the server by doing ./up.sh"
    echo "bye!"
fi

如何运行up.sh脚本?

如果
up.sh
文件与包含上述代码的文件位于同一目录中,则可以执行以下操作

echo "Great! Launching the servers for you..."
$(dirname $0)/up.sh

变量
$0
是当前脚本的路径,
dirname
去掉路径的最后一段,
$(…)
dirname
的输出转换为字符串。

如果
up.sh
文件与包含上述代码的文件位于同一目录中,则可以执行此操作

echo "Great! Launching the servers for you..."
$(dirname $0)/up.sh

变量
$0
是当前脚本的路径,
dirname
去掉路径的最后一段,
$(…)
dirname
的输出转换为字符串。

如果
up.sh
文件与包含上述代码的文件位于同一目录中,则可以执行此操作

echo "Great! Launching the servers for you..."
$(dirname $0)/up.sh

变量
$0
是当前脚本的路径,
dirname
去掉路径的最后一段,
$(…)
dirname
的输出转换为字符串。

如果
up.sh
文件与包含上述代码的文件位于同一目录中,则可以执行此操作

echo "Great! Launching the servers for you..."
$(dirname $0)/up.sh

变量
$0
是当前脚本的路径,
dirname
去掉路径的最后一段,
$(…)
dirname
的输出转换为字符串。

为了避免
cd
-ing混乱,只需在子shell中运行部分,如:

#!/bin/bash

(
# Install angular components - in shubshell
echo "Installing Angular Components..."
cd angApp
npm install
)

(
# Install Server components - again in subshell
echo "Installing Backend Components..."
cd APIServer
#do something here
)    

# go back to main dir
#cd .. #not needed, you're now in the parent shell...

# ask to see if we should launch server
echo "Do you want to launch the server now? Enter (yes/no)  "
read shouldLaunch

# Launch if requested. Otherwise end build
if [ "$shouldLaunch" == "yes" ]; then
    echo "Great! Launching the servers for you..."
    sh up.sh
else
    echo "No problem..."
    echo "you can launch the server by doing ./up.sh"
    echo "bye!"
fi

为了避免cd的混乱,只需在子shell中运行部件,如:

#!/bin/bash

(
# Install angular components - in shubshell
echo "Installing Angular Components..."
cd angApp
npm install
)

(
# Install Server components - again in subshell
echo "Installing Backend Components..."
cd APIServer
#do something here
)    

# go back to main dir
#cd .. #not needed, you're now in the parent shell...

# ask to see if we should launch server
echo "Do you want to launch the server now? Enter (yes/no)  "
read shouldLaunch

# Launch if requested. Otherwise end build
if [ "$shouldLaunch" == "yes" ]; then
    echo "Great! Launching the servers for you..."
    sh up.sh
else
    echo "No problem..."
    echo "you can launch the server by doing ./up.sh"
    echo "bye!"
fi

为了避免cd的混乱,只需在子shell中运行部件,如:

#!/bin/bash

(
# Install angular components - in shubshell
echo "Installing Angular Components..."
cd angApp
npm install
)

(
# Install Server components - again in subshell
echo "Installing Backend Components..."
cd APIServer
#do something here
)    

# go back to main dir
#cd .. #not needed, you're now in the parent shell...

# ask to see if we should launch server
echo "Do you want to launch the server now? Enter (yes/no)  "
read shouldLaunch

# Launch if requested. Otherwise end build
if [ "$shouldLaunch" == "yes" ]; then
    echo "Great! Launching the servers for you..."
    sh up.sh
else
    echo "No problem..."
    echo "you can launch the server by doing ./up.sh"
    echo "bye!"
fi

为了避免cd的混乱,只需在子shell中运行部件,如:

#!/bin/bash

(
# Install angular components - in shubshell
echo "Installing Angular Components..."
cd angApp
npm install
)

(
# Install Server components - again in subshell
echo "Installing Backend Components..."
cd APIServer
#do something here
)    

# go back to main dir
#cd .. #not needed, you're now in the parent shell...

# ask to see if we should launch server
echo "Do you want to launch the server now? Enter (yes/no)  "
read shouldLaunch

# Launch if requested. Otherwise end build
if [ "$shouldLaunch" == "yes" ]; then
    echo "Great! Launching the servers for you..."
    sh up.sh
else
    echo "No problem..."
    echo "you can launch the server by doing ./up.sh"
    echo "bye!"
fi

你得到了什么错误?up.sh:没有这样的文件或目录你做了一些
cd
ing。运行
pwd
echo$pwd
检查您在尝试运行
up.sh
时是否在正确的目录中。您会遇到什么错误?up.sh:没有这样的文件或目录您已经执行了一些
cd
操作。运行
pwd
echo$pwd
检查您在尝试运行
up.sh
时是否在正确的目录中。您会遇到什么错误?up.sh:没有这样的文件或目录您已经执行了一些
cd
操作。运行
pwd
echo$pwd
检查您在尝试运行
up.sh
时是否在正确的目录中。您会遇到什么错误?up.sh:没有这样的文件或目录您已经执行了一些
cd
操作。运行
pwd
echo$pwd
检查您在尝试运行
up.sh
时是否在正确的目录中。