运行 shell 脚本开始新的 shell 而不是 运行 shell 脚本
running shell script starts new shell instead of running the shell script
我不知道该用什么标题。欢迎提出标题建议。
我正在使用 zsh 作为我正在使用的用户的默认 shell。每当我尝试 运行 使用 bash 的脚本时,它都会启动 zsh 的新登录 shell,而不是 运行ning 脚本。如果我将 #!/bin/bash 行更改为 #!/usr/bin/zsh 它就可以正常工作。这是踢球者。启动新的 shell 后,脚本从那时起开始正常工作。
我使用 mate-terminal 和 vcxsrv 作为 X 服务器。我最初启动了一个普通的 ubuntu bash 终端,然后我用它来生成 mate-terminal,因为我需要 DISPLAY var 设置以及在启动 mate-terminal 之前不需要的东西。无论如何,这是我要启动的脚本。
同样重要的是要注意,如果我通过将 bash 设置为默认值并在脚本中使用 zsh 来反转 shells,则不会发生同样的事情。
我如何制作这个 运行 脚本?
$ cat tmp.sh
#!/bin/bash -x
echo hello
$ ./tmp.sh
+ source /usr/sbin/start-systemd-namespace
++ SYSTEMD_EXE='/lib/systemd/systemd --system-unit=basic.target'
+++ ps -eo pid=,args=
+++ awk '" "=="/lib/systemd/systemd --system-unit=basic.target" {print }'
++ SYSTEMD_PID=562
++ '[' myuser '!=' root ']'
++ '[' -z 562 ']'
++ '[' 562 '!=' 1 ']'
++ export
++ sed -e 's/^declare -x //;/^IFS=".*[^"]$/{N;s/\n//}'
++ grep -E -v '^(BASH|BASH_ENV|DIRSTACK|EUID|GROUPS|HOME|HOSTNAME|IFS|LANG|LOGNAME|MACHTYPE|MAIL|NAME|OLDPWD|OPTERR|OSTYPE|PATH|PIPESTATUS|POSIXLY_CORRECT|PPID|PS1|PS4|SHELL|SHELLOPTS|SHLVL|SYSTEMD_PID|UID|USER|_)(=|$)'
++ export 'PRE_NAMESPACE_PATH=/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.rbenv/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.nvm/versions/node/v14.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2020.812.0_x64__79rhkp1fndgsc:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Android:/mnt/c/Windows/System32:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/trent/AppData/Local/Microsoft/WindowsApps:/home/myuser/go/bin:/home/myuser/.local/bin:/home/myuser/go/bin:/home/myuser/.local/bin'
++ PRE_NAMESPACE_PATH='/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.rbenv/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.nvm/versions/node/v14.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2020.812.0_x64__79rhkp1fndgsc:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Android:/mnt/c/Windows/System32:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/trent/AppData/Local/Microsoft/WindowsApps:/home/myuser/go/bin:/home/myuser/.local/bin:/home/myuser/go/bin:/home/myuser/.local/bin'
+++ pwd
++ export PRE_NAMESPACE_PWD=/home/myuser
++ PRE_NAMESPACE_PWD=/home/myuser
++ exec sudo /usr/sbin/enter-systemd-namespace ''
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 4.19.128-microsoft-standard x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon Oct 12 21:48:02 MDT 2020
System load: 0.0 Processes: 66
Usage of /: 7.2% of 250.98GB Users logged in: 0
Memory usage: 7% IPv4 address for eth0: 172.26.153.138
Swap usage: 0%
* Kubernetes 1.19 is out! Get it in one command with:
sudo snap install microk8s --channel=1.19 --classic
https://microk8s.io/ has docs and details.
21 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Last login: Mon Oct 12 21:42:37 MDT 2020 on pts/3
* keychain 2.8.5 ~ http://www.funtoo.org
* Found existing ssh-agent: 108201
* Known ssh key: /home/myuser/.ssh/id_rsa
关键是 /etc/bash.bashrc
中的这一行
source /usr/sbin/start-systemd-namespace
不久前,我根据网上其他地方的一些说明让 systemd 工作。它必须添加这一行。当您使用另一个 shell(如 zsh)时,它会导致一个全新的 shell 启动。注释掉后,瞧,没问题了。
我不知道该用什么标题。欢迎提出标题建议。
我正在使用 zsh 作为我正在使用的用户的默认 shell。每当我尝试 运行 使用 bash 的脚本时,它都会启动 zsh 的新登录 shell,而不是 运行ning 脚本。如果我将 #!/bin/bash 行更改为 #!/usr/bin/zsh 它就可以正常工作。这是踢球者。启动新的 shell 后,脚本从那时起开始正常工作。
我使用 mate-terminal 和 vcxsrv 作为 X 服务器。我最初启动了一个普通的 ubuntu bash 终端,然后我用它来生成 mate-terminal,因为我需要 DISPLAY var 设置以及在启动 mate-terminal 之前不需要的东西。无论如何,这是我要启动的脚本。
同样重要的是要注意,如果我通过将 bash 设置为默认值并在脚本中使用 zsh 来反转 shells,则不会发生同样的事情。
我如何制作这个 运行 脚本?
$ cat tmp.sh
#!/bin/bash -x
echo hello
$ ./tmp.sh
+ source /usr/sbin/start-systemd-namespace
++ SYSTEMD_EXE='/lib/systemd/systemd --system-unit=basic.target'
+++ ps -eo pid=,args=
+++ awk '" "=="/lib/systemd/systemd --system-unit=basic.target" {print }'
++ SYSTEMD_PID=562
++ '[' myuser '!=' root ']'
++ '[' -z 562 ']'
++ '[' 562 '!=' 1 ']'
++ export
++ sed -e 's/^declare -x //;/^IFS=".*[^"]$/{N;s/\n//}'
++ grep -E -v '^(BASH|BASH_ENV|DIRSTACK|EUID|GROUPS|HOME|HOSTNAME|IFS|LANG|LOGNAME|MACHTYPE|MAIL|NAME|OLDPWD|OPTERR|OSTYPE|PATH|PIPESTATUS|POSIXLY_CORRECT|PPID|PS1|PS4|SHELL|SHELLOPTS|SHLVL|SYSTEMD_PID|UID|USER|_)(=|$)'
++ export 'PRE_NAMESPACE_PATH=/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.rbenv/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.nvm/versions/node/v14.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2020.812.0_x64__79rhkp1fndgsc:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Android:/mnt/c/Windows/System32:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/trent/AppData/Local/Microsoft/WindowsApps:/home/myuser/go/bin:/home/myuser/.local/bin:/home/myuser/go/bin:/home/myuser/.local/bin'
++ PRE_NAMESPACE_PATH='/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.rbenv/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/home/myuser/bin:/home/myuser/.nvm/versions/node/v14.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2020.812.0_x64__79rhkp1fndgsc:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Android:/mnt/c/Windows/System32:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/trent/AppData/Local/Microsoft/WindowsApps:/home/myuser/go/bin:/home/myuser/.local/bin:/home/myuser/go/bin:/home/myuser/.local/bin'
+++ pwd
++ export PRE_NAMESPACE_PWD=/home/myuser
++ PRE_NAMESPACE_PWD=/home/myuser
++ exec sudo /usr/sbin/enter-systemd-namespace ''
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 4.19.128-microsoft-standard x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon Oct 12 21:48:02 MDT 2020
System load: 0.0 Processes: 66
Usage of /: 7.2% of 250.98GB Users logged in: 0
Memory usage: 7% IPv4 address for eth0: 172.26.153.138
Swap usage: 0%
* Kubernetes 1.19 is out! Get it in one command with:
sudo snap install microk8s --channel=1.19 --classic
https://microk8s.io/ has docs and details.
21 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Last login: Mon Oct 12 21:42:37 MDT 2020 on pts/3
* keychain 2.8.5 ~ http://www.funtoo.org
* Found existing ssh-agent: 108201
* Known ssh key: /home/myuser/.ssh/id_rsa
关键是 /etc/bash.bashrc
中的这一行source /usr/sbin/start-systemd-namespace
不久前,我根据网上其他地方的一些说明让 systemd 工作。它必须添加这一行。当您使用另一个 shell(如 zsh)时,它会导致一个全新的 shell 启动。注释掉后,瞧,没问题了。