2

I'm trying to write a simple shell script for launching commands with urxvt. The idea is this (not the complete script, just the idea):

PRMPT="read -r CMD"
urxvt -g 55x6-20+20 -e $PRMPT
CMD

There are two problems with this script. The first one is that read is not fit for this kind of task, as it would ignore options of a command (if I write echo hello read would assign echo to CMD and ignore hello). The second one, which is the one that puzzles me most, is that urxvt -e exits immediately and does not wait for my input. I figure that it has to do with the fact that read is a builtin function, but for example urxvt -e echo hello works fine.

Does anybody have any suggestions on how to change the script?

  • 2
    What is your goal? – Wildcard Aug 16 '16 at 18:40
  • "suggestion"..: by reading the urxvt man page (which is a worthy read), one learns that like most terminal programs it essentially does whatever is designed by "-e" and when that's done it's done. sooo... if you want to run shell commands, give it a shell thusly: urxvt -e sh -c "shell commands" – Theophrastus Aug 16 '16 at 18:45
1

what is your goal? echo is executable (/bin/echo), read is builtin. -e means execute an executable. If you wanna use a builtin function of your shell (bash?) use urxvt -e /bin/bash -c read -r CMD

1

I don't know urxvt, but can help you with read.

When you use read this way:

read -r CMD

It assigns the first token it reads to the variable CMD. If you want to read more tokens, you can state more variables explicitly.

read -r CMD ARGS1 ARG2 ARG3

In this case, if there are more tokens than variables to which they should be assigned, the last variable takes what it's intuitively supposed to plus the rest of the tokens read.

You can also use an array, by adding the -a option.

read -ra CMD

To expand an array, do:

"${CMD[@]}"

Illustration.

$ read -a cmd
echo ok
$ ${cmd[@]}
ok

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.