0

I am basing my question on the thread here: How can I run a specific line as a command in a text file?

How do I run a set of lines from the the text file?

Here's what I have tried so far:

Input file:
      1 #!/usr/bin/csh -v
      2
      3 date
      4
      5 echo "abc"
      6
      7 set cell="bananas"
      8
      9   set cmd = "echo apples \
     10               oranges \
     11               graped $cell"
     12
     13 echo $cmd
     14

sed -n '5,13 p' /tmp/1 | sh

gives:

abc
(blank line)

Why doesn't this execute the rest of the lines? Or as I suspect, is it running it but not giving any output since these commands are run in a new? sh(ell) everytime and not in a single shell session?

Thanks!

2
  • I would strongly urge you to read Csh Programming Considered Harmful to see why using csh as a scripting language (it is fine as a shell) is a very bad idea.
    – terdon
    May 21 at 17:03
  • @terdon will do. Thank you. my intent here is simply to have frequently used c-shell commands and/or 1-liner scripts saved into a text file that I can re-use whenever needed to avoid typing. May 21 at 17:46
3

Your test is failing because you’re using a different shell, sh, instead of the shell expected by the script, csh.

sed -n 5,13p /tmp/1 | csh

will produce the results you expect.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.