LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Take arguments of console command from file (https://www.linuxquestions.org/questions/linux-general-1/take-arguments-of-console-command-from-file-212971/)

RedDwarf 08-03-2004 12:34 PM

Take arguments of console command from file
 
It's possible to use the contents from a file and not the file itself how arguments of a console command?

Thanks

Dark_Helmet 08-03-2004 12:45 PM

It's possible, but depends on the contents of the file. If the only thing in the file are arguments you want to use, then you can do this:

command `cat filename`

Those are backticks ( ` ) not single quotes ( ' ). The shell will repace the backticks with the output of the command inside the backticks.

RedDwarf 08-03-2004 02:35 PM

Thanks, but now I have another problem. If some of the arguments are filenames with spaces? Now it interpretes every word like an argument.

When working with such filenames normally I quote them or use "\ ", perhaps there is some other way using "\<ASCII code>" or something that doesn't uses spaces?

Dark_Helmet 08-03-2004 03:05 PM

Then you would need to add the escape sequences in the file itself, or surround the filenames with double quotes. Such as:

Code:

/path/to/some\ file
or
Code:

"/path/to/some file"

RedDwarf 08-03-2004 04:09 PM

Doesn't work, gives:

Code:

/path/to/some\ : No such file or directory
file : No such file or directory

or

Code:

"/path/to/some : No such file or directory
file" : No such file or directoryjhggg


Dark_Helmet 08-03-2004 06:12 PM

Ugh... my mistake... I should have tested it before opening my mouth. That's a bit odd though. To my knowledge, the shell should have interpreted that text exactly as if it had been typed at a prompt.

I couldn't get things to work with a number of different gyrations I tried on my own. You may have to use a small shell script.


All times are GMT -5. The time now is 02:36 PM.