LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Silencing the line "echo test > test/test.txt" in a shell script (http://www.linuxquestions.org/questions/linux-general-1/silencing-the-line-echo-test-test-test-txt-in-a-shell-script-814926/)

Arenlor 06-18-2010 09:12 AM

Silencing the line "echo test > test/test.txt" in a shell script
 
I tried surrounding it with set +v and set -v but that did not do what I want. It always echo's test to stdout along with the file. It's line 15 below:
Code:

#!/bin/bash
echo "Testing Floppy..."
mkdir test
if [ ! -d test ]
  then
    echo "Problem creating directory."
    exit 1
fi
touch test/test.txt
if [ ! -f test/test.txt ]
  then
    echo "Problem creating file."
    exit 1
fi
echo test > test/test.txt
if ! cat test/test.txt | grep -e test
  then
    echo "Problem writing to file."
    exit 1
fi
rm test/test.txt
if [ -f test/test.txt ]
  then
    echo "Problem deleting file."
    exit 1
fi
rm -r test
if [ -d test ]
  then
    echo "Problem deleting directory."
    exit 1
fi
if [ -a test/test.txt -o -a test ]
  then
    echo "Curiouser and curiouser. Things are FUBAR."
    exit 1
fi
echo "No problems, floppy drive is good!"

Heh yes, floppies.

Kenhelm 06-18-2010 10:01 AM

It's grep which needs to be silenced. Try
Code:

if ! cat test/test.txt | grep -q -e test

Arenlor 06-18-2010 01:37 PM

Thanks, and that's why I always post full source, never know if I actually know what a problem is.


All times are GMT -5. The time now is 05:27 PM.