Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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?

var=somestring
echo $var

That prints simplestring on the console

But this...

var=somestring
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
date

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

 
discard

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.