Run bash command inside zsh script

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run bash command inside zsh script
# 1  
Question Run bash command inside zsh script

I would like to run following code in bash inside a zsh script. (In this case is output unfortunately very different if you run it in zsh).

I tried to put "bash" in front of the code but I obtained following error message "bash: do: No such file or directory
" eve though I merged the whole code into one line.
Could anyone help?

bases=`echo A T G C` 

for c1 in $bases
    for c2 in $bases 
        for c3 in $bases
        echo $c1$c2$c3

# 2  
bash -c 'b="A T G C"; for c1 in $b;do for c2 in $b;do for c3 in $b; do echo $c1$c2$c3;done;done;done'

Hope this works/helps...

Update: The commands don't need to be squashed in one line though
bash -c 'b="A T G C"
for c1 in $b; do
 for c2 in $b; do
  for c3 in $b; do
   echo $c1$c2$c3

Last edited by junior-helper; 12-03-2014 at 05:03 AM.. Reason: see update
This User Gave Thanks to junior-helper For This Post:
# 3  
But, of course, if you change:
bases=`echo A T G C`

bases=$(echo A T G C)

your script should work just fine with bash, ksh, or zsh. And, if you use the much simpler and more efficient:
bases="A T G C"

bases='A T G C'

your script should work just fine with any shell based on Bourne shell syntax (such as ash, bash, ksh, zsh, or on almost any UNIX or Linux system /bin/sh.

Last edited by Don Cragun; 12-03-2014 at 04:46 AM.. Reason: Go back to original post.
This User Gave Thanks to Don Cragun For This Post:
# 4  
This would be much easier. But if I try it I obtain:

---------- Post updated at 02:38 AM ---------- Previous update was at 02:37 AM ----------
# 5  
I apologize. I don't use zsh. I had assumed that it was rejecting the old form of command substitution, but zsh (at least on OS X) does not seem to perform field splitting as required by the standards on the unquoted expansion of a variable. Do you have to use zsh for your script instead of running the entire script with bash or ksh?
# 6  
zsh is more user friendly for me, so I usually use it. This command should be a minor part of another zsh script.
The other suggesteg solution works, so I'm OK
bash -c 'b="A T G C"; for c1 in $b;do for c2 in $b;do for c3 in $b; do echo $c1$c2$c3;done;done;done'
# 7  
It appears that you could make your original script work in zsh without needing to invoke bash using:
bases="A T G C"
set -o shwordsplit
for c1 in $bases
do  for c2 in $bases 
    do  for c3 in $bases
        do  echo $c1$c2$c3

And, if you wanted to disable standard shell word splitting after executing the nested loops, you could add:
set +o shwordsplit

after the last done.
This User Gave Thanks to Don Cragun For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #145
Difficulty: Easy
Unix popularized the hierarchical file system with arbitrarily nested subdirectories, originally introduced by Multics.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Run awk command inside ssh

I am trying to run an awk command inside of ssh and it is not working. These are AIX servers. for i in `cat servers`; do ssh $i "/bin/hostname; df -g | awk '/dev/ && $4+0 > 70'"; done server1 server2 server3 server4 I also tried these two methods and they did not work. It just seemed... (5 Replies)
Discussion started by: cokedude
5 Replies

2. Shell Programming and Scripting

Executing sed command inside a bash script

I want to run commands inside a bash script. An example is I want to pass the command in a string as regexp as an argument to the script, then run sed on the bash variable regexp "-i \"s/<p>//g\"" then call sed "$regexp" $fl (3 Replies)
Discussion started by: Kangol
3 Replies

3. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

4. Shell Programming and Scripting

Listen sharp time to run a command inside a script

Hello, Just wondered if there is any possibility to run a command at sharp time inside a script in linux. My question is not about crontab Example: #!/bin/bash cd /home/database for i in * do command 1 if time is 19:00, day is Monday then run command2 if time is 20:00, day is... (10 Replies)
Discussion started by: baris35
10 Replies

5. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

6. Shell Programming and Scripting

Bash- Command run from script does not pass full parameters with spaces inside

There's a JavaScript file that I call from command line (there's a framework) like so: ./RunDiag.js param1:'string one here' param2:'string two here' I have a shell script where I invoke the above command. I can run it in a script as simple as this #!/bin/bash stuff="./RunDiag.js... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

7. Shell Programming and Scripting

Preserve extented ascii character when run echo comand inside bash script

Hi everyone, I'm echo some text with extended ascii characters as below: echo -e "Pr\xE9sentation du spectacle" > output or echo -e "Présentation du spectacle" > outputIf I open the file created I see this text Présentation du spectacleThe text is shown correctly in this created file when... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

8. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi "" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

9. Shell Programming and Scripting

ZSH - '.zlogout' not being run on exit

Hi, I have a problem with '.zlogout' not being run on Solaris 10. Here's whats happening. I remotely log in from a PC running Cygwin/X using a local xterm window and ssh to start a remote 'zsh' shell, version 4.2.5, on a Solaris 10 server. The Server has KDE installed but as a Window... (0 Replies)
Discussion started by: stv_t
0 Replies

10. Shell Programming and Scripting

Run the command inside perl script

I have a command which will run fine in a unix command prompt. Can you tell how to interprete this command inside perl script...... The command is : perl -pe 's/(\|333\}.*)\}$/$1|1.6}/' FIA.txt This will search for the number 333 and appends 1.6 at the end of that line....... (1 Reply)
Discussion started by: vinay123
1 Replies

Featured Tech Videos