1

I have a Bash script that runs 3 commands. The last file is called "junk1.txt" which I am worrying about. I want to make an addition to the check the if statement performs. If the "junk1.txt" is an ASCII text file. How would I go about doing this?

./command1 > command1.txt

while read l;

do
    command2 > command2.txt

    while read m;

        do

            command3 junk.txt > junk1.txt 2>/tmp/err
            if [ -s /tmp/err ] #I WANT TO ADD ANOTHER CONDITION HERE
            then
                echo "not cracked"
            else
                echo "cracked"
                exit
            fi
        done < command2.txt

done < command1.txt
1
  • You can't check if it is. You can only check if it could be or could not be. It is whatever the author chose. Commented Sep 25, 2018 at 13:40

2 Answers 2

2

You can use file to test this:

For your use case replace your if [ -s /tmp/err ] line with:

if [ -s /tmp/err ] && [ "$(file junk1.txt)" = "junk1.txt: ASCII text" ]
Sign up to request clarification or add additional context in comments.

Comments

1

Use strings command:

if diff <(strings ascii.txt) ascii.txt; then ... 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.