Say, I modify a lot of code that uses tcsh, but since a lot of people say that bash is more modern, I'd also like to learn bash along the way. Is it possible for me to use a script that contains both of these commands at the same time? Since this is for personal use, elegance is not an issue.
|
No, it is not possible. The reason is that the shell reads in chunks of the file as it executes it, and a chunk might contain shell code that you want to run in a different shell, but since its already been read by the first shell, the second shell cant read it if it were to take over execution of the script. (This could work if the shell had the ability to However there is a dirty way of doing this; zsh. . Also I wouldnt say bash is more modern. It's more widespread sure, but it adopts features at a very slow pace. Bash is more focused on compatibility than anything. |
|||
|
|
I wouldn't recommend mixing and matching shell types within a script.
I would say your best bet would be to copy a known script and change the calling shell, and then see what breaks, so you know where the differences in syntax are that have to be worked out. But, in short, trying to mix and match within a script just seems like a bad idea. (personally) |
|||
|
|
|
I agree with the other answers that it's not generally a great idea. But you can invoke a shell from a script. If you have a script currently written to use tcsh and you want to use a few bash-specific features, you can invoke bash explicitly. For example, bash makes it much easier to redirect stdout and stderr independently.
In the long run, though, it's probably better to translate the entire script to use bash. Obligatory link: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ |
|||
|
|