|
-
February 13th, 2011, 11:53 PM
#1
[RESOLVED] Passing program arguments
This is probably more of a unix bash shell question, but I didn't know where else to post. My apologies if this is the wrong forum for this question.
Here is a file with the following contents (4 lines, let's call the file f)...
hello
a b c
“d e f”
'x y z'
Note the double and single quotes on some of the lines.
Here's a C++ program (let's call it nargs)...
Code:
#include <iostream>
int main (int argv, char* argc [])
{
std::cout << “\n argv = “ << argv << std::endl;
}
1) Executing the following command from the bash shell will output the following...
$ while read line; do printf “$line “; done < f
hello a b c “d e f” 'x y z'
2) Executing the following command from the bash shell will output the following...
$ nargs hello a b c “d e f” 'x y z'
argv = 7
3) Executing the following command from the bash shell will output the following...
$ nargs $(while read line; do printf “$line “; done < f)
argv = 11
What is going on here? I know the shell is performing some kind of translation regarding the quotes, but why the inconsistency? In #1, the quotes are present in the output. In #2, I've physically typed the quotes, just like they've appeared in #1. In #3, the quotes are obviously gone since the C++ program received 11 arguments, vice 7 in #2.
I've also tried using backslashes between the spaces instead of quotes. This doesn't work either. Is there a way to get around this problem? I haven't run across any shell settings to solve this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|