Skip to main content
deleted 26 characters in body
Source Link
outlyer
  • 1.1k
  • 7
  • 11

You're trying to execute $file. Instead, you must echo it:

# ...
if echo "$file" | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use parenthesesquotes if you expect it to work with any file, but you're right in that that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

You're trying to execute $file. Instead, you must echo it:

# ...
if echo "$file" | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use parentheses if you expect it to work with any file, but you're right in that that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

You're trying to execute $file. Instead, you must echo it:

# ...
if echo "$file" | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use quotes if you expect it to work with any file, but that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

added 2 characters in body
Source Link
terdon
  • 252.3k
  • 69
  • 480
  • 718

You're trying to execute $file. Instead, you must echo it:

# ...
if echo $file"$file" | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use parentheses if you expect it to work with any file, but you're right in that that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

You're trying to execute $file. Instead, you must echo it:

# ...
if echo $file | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use parentheses if you expect it to work with any file, but you're right in that that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

You're trying to execute $file. Instead, you must echo it:

# ...
if echo "$file" | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use parentheses if you expect it to work with any file, but you're right in that that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

added 83 characters in body
Source Link
outlyer
  • 1.1k
  • 7
  • 11

You're trying to execute $file. Instead, you must echo it:

# ...
if echo $file | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use parentheses if you expect it to work with any file, but you're right in that that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

You're trying to execute $file. Instead, you must echo it:

# ...
if echo $file | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do

Also, you might want to use parentheses if you expect it to work with any file, but you're right in that that's not the source of the problem.

You're trying to execute $file. Instead, you must echo it:

# ...
if echo $file | grep 'o' ;
# ...

Note that the grep will already print the filename, so you should silence it (e.g. grep -q 'o' or grep 'o' >/dev/null).

You're also passing -l to ls, which you don't want to do. ls -l prints the file name and attributes, and you'll be matching against them.

Also, you might want to use parentheses if you expect it to work with any file, but you're right in that that's not the source of the problem.

P.S.: As others have pointed out, you shouldn't use ls to begin with.

Source Link
outlyer
  • 1.1k
  • 7
  • 11
Loading