运行shell脚本将启动新的shell,而不是运行shell脚本

  • 本文关键字:shell 运行 脚本 启动 bash wsl-2
  • 更新时间 :
  • 英文 :


我不知道该怎么命名。欢迎标题建议。

我使用zsh作为我正在使用的用户的默认shell。每当我尝试运行一个使用bash的脚本时,它就会启动一个新的zsh登录shell,而不是运行该脚本。如果我更改#/bin/bash行到#/usr/bin/zsh它只是工作。踢球者来了。一旦新的shell启动,脚本就从那时开始正常工作

我正在使用vcxsrv作为X服务器的mate终端。我最初启动了一个普通的ubuntu bash终端,然后我用它来生成mate终端,因为在启动mate终端之前,我需要DISPLAY var设置。不管怎样,这是我要开始的剧本。

同样需要注意的是,如果我通过将bash设置为默认值并在脚本中使用zsh来反转shell,那么同样的事情就不会发生。

我如何让它只运行脚本?

$ 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 '$2" "$3=="/lib/systemd/systemd --system-unit=basic.target" {print $1}'
++ 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.bashc 中的这一行

source /usr/sbin/start-systemd-namespace

回来后,我根据网上其他地方的指示进行了系统工作。它一定添加了这一行。当您使用另一个类似zsh的shell时,它会启动一个全新的shell。说完了,瞧,没问题了。

相关内容

  • 没有找到相关文章

最新更新