0

The simple script below does not work when, rather than passing a single file name, I want to pass multiple files through expansion characters like *

#!/bin/bash
fgrep -c '$$$$' $1

If I give the command script.sh file.in the script works. If I give the command script.sh *.in it doesn't.

2
  • $1 is not set to *.in; it's set to the first item that *.in expands to. Commented Feb 18, 2014 at 13:49
  • @chepner which might be *.in, if no matching files exist. ;) Commented Feb 19, 2014 at 2:14

1 Answer 1

5

Use "$@" to pass multiple file names to fgrep. $1 only passes the very first file name.

fgrep -c '$$$$' "$@"
Sign up to request clarification or add additional context in comments.

1 Comment

@mimenico Note that $1 is a subset of $@, referring to exactly the first argument; also, quoting is (usually) better than not quoting:therefore, $@ is better than $*.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.