1

I am trying to use a shell script which contains the following command :

(./rstrings $INPUT ; cat $INPUT ) | sha1sum

When I run the above command in the terminal, i get the desired output, whereas in my shell script, the same command gives me command not found. Below is the line in the script creating issues :

sha1 = `(./rstrings $INPUT ; cat $INPUT ) | sha1sum`

rstrings is a c executible...

I am new to shell scripting and any help would be appreciated!

3
  • You're using a relative path, you're probably not in the right directory when that line is exeuted. Commented Sep 24, 2017 at 19:09
  • I ran the command in the same directory as the shell script and the c executable... Commented Sep 24, 2017 at 19:10
  • 2
    Thank you Cyrus, shellcheck.net helped me find my mistake...I was using extra spaces during assignment...coming from mainstream programming languages caused me to miss this Commented Sep 24, 2017 at 19:17

1 Answer 1

2

I got my mistake, I should have kept spaces out of the assignment.

sha1 = `(./rstrings $INPUT ; cat $INPUT ) | sha1sum`

The statement below reflects the changes required :

sha1=`(./rstrings $INPUT ; cat $INPUT ) | sha1sum`

For all other new shell scripters, spaces while assignment is not allowed. http://www.shellcheck.net/ is really helpful to follow best practices in shell scripting and I thank Cyrus for guiding me towards it.

Sign up to request clarification or add additional context in comments.

1 Comment

Correct. On the other hand, spaces are required in test expressions (e.g. if [ "$x" = "$y" ] will work, but if [ "$x"="$y" ] will not do what you expect, and if ["$x" = "$y"] won't work at all). Spaces are important delimiters in shell syntax, so don't add or remove them unless it's in one of the (few) specific places where it doesn't change the meaning. And yes, shellcheck.net is your friend.

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.