Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a linux script that generates a string and prints it to the console. I want this string to be the name of a file and open it for editing in vi. How can this be done?

share|improve this question
up vote 2 down vote accepted

You can try with:

vi -- "$(your-script)"
share|improve this answer

Use the backtick char to escape the script: (on the same key as the tilde ~ char)

vi `./script`

And if the output has spaces that you stil want to see as a single parameter:

vi "`./script`"

test it:

vi "`echo This is my new filename.txt`"

share|improve this answer

Does your script do this?

echo $var

That prints simplestring on the console

But this...

date >$var

will create a file named somestring and put the date and time into it. But maybe you want to be really clever...

echo -n What file should I use for the log?
read var
exec >$var 2>&1

The -n tells echo not to emit a newline. The exec command doesn't execute anything, just changes the stdout (#1) and stderr (#2). The 2>&1 says to make 2 (stderr) go to the same place as 1 (stdout).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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