When I run this on the command line it works:
ls | grep -v "#$"
But when I do ls | scriptname and inside the script I have:
#fileformat=unix
#!/bin/bash
grep -iv '#$'
It’s not working. Why?
[EDIT]
the reason for the first line is explained here.
besides that even if i remove the first two lines it SHOULD work. i tried the exact same on a remote Solaris account and it did work. so is it my Fedora installation?
The hash-bang line needs to be the first line in the script. Get rid of the
#fileformat=unix. Also make sure your script is executable (chmod +x scriptname). This works:Change it to
ls < scriptnameso that the output is passed to ls.1st off you need #! /bin/bash as the first line in your script.
Then ‘#$’ has no meaning in the shell pantheon of parameters. Are you searching for a ‘#’ at the end of the line? (That is OK). But if you meant ‘$#’ but then $# is the parameter that means the ‘number of arguments on the command-line’
Generally, piping a list of files to a script to acted on would have to be accomplished with further wrapper. So a bare-bones, general solution to the problem you pose might be :
called as
I hope this helps.