LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-03-2004, 12:34 PM   #1
RedDwarf
LQ Newbie
 
Registered: Aug 2004
Posts: 25

Rep: Reputation: 15
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
 
Old 08-03-2004, 12:45 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.

Last edited by Dark_Helmet; 08-03-2004 at 12:46 PM.
 
Old 08-03-2004, 02:35 PM   #3
RedDwarf
LQ Newbie
 
Registered: Aug 2004
Posts: 25

Original Poster
Rep: Reputation: 15
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?

Last edited by RedDwarf; 08-03-2004 at 02:41 PM.
 
Old 08-03-2004, 03:05 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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"
 
Old 08-03-2004, 04:09 PM   #5
RedDwarf
LQ Newbie
 
Registered: Aug 2004
Posts: 25

Original Poster
Rep: Reputation: 15
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
 
Old 08-03-2004, 06:12 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH Script: variable values referencing for console arguments sadarax Programming 1 11-14-2005 05:23 PM
passing a list of arguments to a command hdagelic Linux - General 2 05-09-2005 09:30 AM
command arguments in perl djgerbavore Programming 1 12-30-2004 08:06 AM
see what arguments are available for a command naijaguy Linux - Newbie 3 08-12-2004 10:05 PM
Help with command line arguments ? synapse Linux - Newbie 2 02-23-2004 02:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration