jhon.smith
jhon.smith

Reputation: 2043

Append contents of one file into another

> for filename in '*.sql'
> do
> echo "@some_string" >> $filename
> done
-bash: $filename: ambiguous redirect

when i try to append a constant to all files i get a error ambigous redirect.

Any idea how to solve this issue ?

Upvotes: 1

Views: 1140

Answers (2)

Arialdo Martini
Arialdo Martini

Reputation: 4577

I'd use

#!/bin/bash
for filename in *.sql
do
echo "@some_string" >> "$filename"
done

The problem with your code is in

cat "@some_string"

since cat expects a filename.

As stated by @c00kiemon5ter, you should also quote $filename, since it could contain spaces.

Upvotes: 1

codaddict
codaddict

Reputation: 455440

Try:

for filename in *.sql
do
echo "@some_string" >> "$filename"
done

Upvotes: 3

Related Questions