[ale] scripts, file I/O, and loss of hair

The Don Lachlan ale-at-ale.org at unpopularminds.org
Thu May 12 17:14:15 EDT 2011


On Thu, May 12, 2011 at 02:10:25PM -0400, Jim Kinney wrote:
> I have a simple test script my_script
> 
> #!/bin/bash
> # this is a crap script
> myout="$2"'.crap'
> directions=$(cat $2)
> echo "$myout"
> echo "$directions"
> exit
> 
> It is launched by:
> ./my_script < test1.dat
> 
> which is a file containing one line
> /tmp/
> 
> which will be used later once the I/O issue is corrected.
> This is being done to replicate a much larger scenario
> 
> When it is run, the output is:
> .crap
> /tmp/
> 
> Notice that the file I want to be named test1.dat.carp is only named .crap
> I need to get the name of the input file into the script itself somehow.
> Positional parameters as not doing it.

Dude,

The redirect < terminates the arguments to your script; everything from the
redirect on is completely separate.

$ ./myscript test1.dat

Then open the file inside your script. Yes, I'm speaking truth.

Also,

  directions=$(cat $2)

should be replaced by

  directions=`<${1}`

See Useless Use of Cat - http://partmaps.org/era/unix/award.html#cat

-L


More information about the Ale mailing list