|
-
Apr 26th, 2008, 06:49 AM
#1
[RESOLVED] #!/bin/bash ??????
I have written a program that takes input from STDIN. It works nicely to read a plain text file called test.rpn when I use the following syntaxes...
Code:
cat test.rpn | myApp
That's all well and good. However I have read up on "shebang" commands that frequently appear at the top of executable text files (shell scripts and so on). I am now trying to use this technique by making test.rpn executable (chmod +x) and adding a shebang line to the top of that file to use the full path to myApp.
When then run the file (./test.rpn) the shell does indeed invoke myApp but since myApp is expecting the data to be read in from STDIN, it cannot understand and exits without doing anything.
Trouble is that "./myapp test.rpn" is not a valid way to start my app, and that justso happens to be the way that shebang lines pass the filename in.
I've tried all sorts of slight changes to the shebang line to try to get it to "<" redirect the filename into myApp but to no avail.
I also tried adding a second level of shebang by adding a normal shell script in between the test.rpn file and the myApp program. But apparently shebang lines are not able to be nested in this way, it just fails with shell "command not found" errors.
I must have tried about 10 ways to do this but nothing seems to work.
I am very reluctant to make myApp read from a filename in the parameter list because of the already complex logic to process the parameter list. I thought doing the shebang trick would be a neat idea that wouldn't require changes to my binary.
Does anyone have a neat idea about how to achieve this?
Last edited by wossname; Apr 26th, 2008 at 08:29 AM.
I don't live here any more.
-
Apr 26th, 2008, 08:40 AM
#2
Fanatic Member
Re: #!/bin/bash ??????
The shebang only tells the Linux OS what shell to use. I personally like to use bash because it has some nice features, and is pretty common in the Linux world.
For example I normally use:
#!/bin/bash
I'm kinda confused on what you want to do, and wondering why you just can't do this:
Code:
#!/bin/bash
cat test.rpn | myApp
Or even take that to another level...
Code:
#!/bin/bash
cat $1 | myApp
And if I remember from my unix class $1 holds the first parameter sent to the script (ie ./script somefile). And $# holds the number of parameters sent to the script.
-
Apr 26th, 2008, 12:54 PM
#3
Last edited by wossname; Apr 27th, 2008 at 08:48 AM.
I don't live here any more.
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
|