如何从bash脚本运行shell脚本
我在运行以下命令时出现错误(在:sh up.sh行上):如何从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 ..
#!/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
时是否在正确的目录中。