linux - 无法在 ZSH 中运行 bash 文件
问题描述
.zshrc
每次打开新的终端窗口或源代码时,我都在其中放置了一个 bash 文件,并尝试了所有不同的方法来运行它,.zshrc
但没有运气。
仅供参考:它运行良好.bashrc
这是.zshrc
脚本:
#Check if ampps is running
bash ~/ampps_runner.sh & disown
不同的方法:
#Check if ampps is running
sh ~/ampps_runner.sh & disown
另一种方法:
#Check if ampps is running
% ~/ampps_runner.sh & disown
上述所有方法都不起作用(这意味着它应该运行一个名为 ampps 的应用程序,但它不在 zsh.
注意:在从 bash 切换到 zsh 之前它工作正常。所以它没有权限或语法问题。
更新: ampps_runner.sh 的内容
#! /usr/bin/env
echo "########################"
echo "Checking for ampps server to be running:"
check=$(pgrep -f "/usr/local/ampps" )
#[ -z "$check" ] && echo "Empty: Yes" || echo "Empty: No"
if [ -z "$check" ]; then
echo "It's not running!"
cd /usr/local/ampps
echo password | sudo -S ./Ampps
else
echo "It's running ..."
fi
解决方案
从终端bash
临时运行的最简单方法是zsh
exec bash
要不就
bash
然后您可以运行以前只能在 bash 中运行的命令。一个例子
help exec
退出
exit
现在你回到了原来的外壳
如果你想知道你的默认 shell
echo $SHELL
或者
set | grep SHELL=
如果你想可靠地知道你当前的 shell
ps -p $$
或者,如果您只想要您可能使用的 shell 名称
ps -p $$ | awk "NR==2" | awk '{ print $4 }' | tr -d '-'
而且您可能只是将最后一个放在一个函数中以备后用,只要知道它只有在它来自当前 shell 时才可用。
whichShell(){
local defaultShell=$(echo $SHELL | tr -d '/bin/')
echo "Default: $defaultShell"
local currentShell=$(ps -p $$ | awk "NR==2" | awk '{ print $4 }' | tr -d '-')
echo "Current: $currentShell"
}
调用方法查看结果
whichShell
推荐阅读
- swift - Swift 无法从 NSView 打印“CGContextGetCTM:无效上下文 0x0”
- java - 将 MS SQL Server 表复制到 SQLite 表
- mysql-python - 在python 3中导入_mysql
- powershell - 通过 catch 块 powershell 时出错
- javascript - 使用 lodash 变换时如何包含已删除的数组项
- laravel - 类别树
- c++ - 展开函数模板的参数包
- python - 字符串列表,替换其他列表中的所有单词
- autoit - 运行函数不执行程序
- javascript - 导航栏在本地服务器和实时服务器上看起来不同,但可以通过文件打开它