[prog] bash script

Benjamin M. A'Lee bma-linuxchix at bma.cx
Sun Jan 23 19:39:35 UTC 2011


Wolf Rising <wolfrising at gmail.com> writes:
> It's a little bash script that checks file types by the first character, I
> wanted to add an if clause but I
> seem to have an error [ "sed -n '/^!-/p' $file" ] as it skips over this an
> prints the echo statement
> whether the file type is found or not.

I think you actually want the following:

  if sed -n  '/^!-/p' $file; then
     ...
  fi

This will execute the if-block if sed returns true. The code you list
tests whether the length of the string "sed -n '/^!-/p' $file" is
non-zero, which is always true.

Hope that helps,

	bma


More information about the Programming mailing list