Shell out into zsh and execute commands from bash script

mcbain83

I'm trying my hand a little virtualisation, so I've been using vagrant to provision a centos7 vm and now I am configuring it with applications.

My vagrant config runs a bootstrap.sh file which is a bash script, in it I install zsh, then I want to configure it as per https://github.com/sorin-ionescu/prezto . step 1 is launch zsh then run some commands.

This is the code I have at the moment.

echo "Installing zsh"
yum install -y zsh

echo "Configure zsh"
# touch /home/vagrant/.zshrc
exec /usr/bin/zsh
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh

I want this to be the default shell when I ssh into the VM. It does not appear to be working, there are no errors with the vagrant up step so I just want to know if this is possible and if this seems correct?

Thanks

Charles Duffy

exec zsh replaces your shell with zsh -- but doesn't in any way tell that instance of zsh to pick up at the same point in execution, or even to run the same script that the bash invocation was previously executing at all.

One easy fix is to feed the rest of your script to zsh via a heredoc:

/usr/bin/zsh <<'EOF'
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
chsh -s /bin/zsh
EOF

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to execute shell commands in a loop from within a bash script?

From Dev

Cannot execute shell commands in bash script

From Dev

Can a bash shell script open a text file with less and then execute less commands from the script?

From Dev

Running a bash script from a zsh shell

From Dev

How to execute git commands from bash script?

From Dev

Bash script to read from a file and execute commands

From Dev

Bash script to read from a file and execute commands

From Dev

How to execute commands in docker container as part of bash shell script

From Dev

bash script, execute shell from another shell and assign results to a variable

From Dev

bash script, execute shell from another shell and assign results to a variable

From Dev

Execute gcloud commands in a bash script

From Dev

Bash script to spawn and execute commands

From Dev

Bash Script execute commands from a file but if cancel on to jump on next one

From Dev

How to execute the vim commands through shell script

From Dev

Make a shell script execute commands in telnet or programs

From Dev

How to execute commands in gnuplot using shell script?

From Dev

how to execute compound commands in shell script?

From Dev

Execute a block of commands without keeping it in shell history (zsh)

From Dev

Execute a block of commands without keeping it in shell history (zsh)

From Dev

bash script execute commands after ssh

From Dev

How to execute the following commands in a bash script?

From Dev

Bash script to execute multiple Unix commands

From Dev

Execute symbolicatecrash from shell script

From Dev

Pass commands to Mongo shell from bash script without halting interactive Mongo shell

From Dev

Shell commands not working when grouped in a bash script

From Dev

How to execute library calls commands from shell?

From Dev

How to execute sudo commands with Expect & send commands in bash script?

From Dev

zsh shell fg command coming from bash?

From Dev

Can't change shell from zsh to bash?

Related Related

  1. 1

    How to execute shell commands in a loop from within a bash script?

  2. 2

    Cannot execute shell commands in bash script

  3. 3

    Can a bash shell script open a text file with less and then execute less commands from the script?

  4. 4

    Running a bash script from a zsh shell

  5. 5

    How to execute git commands from bash script?

  6. 6

    Bash script to read from a file and execute commands

  7. 7

    Bash script to read from a file and execute commands

  8. 8

    How to execute commands in docker container as part of bash shell script

  9. 9

    bash script, execute shell from another shell and assign results to a variable

  10. 10

    bash script, execute shell from another shell and assign results to a variable

  11. 11

    Execute gcloud commands in a bash script

  12. 12

    Bash script to spawn and execute commands

  13. 13

    Bash Script execute commands from a file but if cancel on to jump on next one

  14. 14

    How to execute the vim commands through shell script

  15. 15

    Make a shell script execute commands in telnet or programs

  16. 16

    How to execute commands in gnuplot using shell script?

  17. 17

    how to execute compound commands in shell script?

  18. 18

    Execute a block of commands without keeping it in shell history (zsh)

  19. 19

    Execute a block of commands without keeping it in shell history (zsh)

  20. 20

    bash script execute commands after ssh

  21. 21

    How to execute the following commands in a bash script?

  22. 22

    Bash script to execute multiple Unix commands

  23. 23

    Execute symbolicatecrash from shell script

  24. 24

    Pass commands to Mongo shell from bash script without halting interactive Mongo shell

  25. 25

    Shell commands not working when grouped in a bash script

  26. 26

    How to execute library calls commands from shell?

  27. 27

    How to execute sudo commands with Expect & send commands in bash script?

  28. 28

    zsh shell fg command coming from bash?

  29. 29

    Can't change shell from zsh to bash?

HotTag

Archive