0

#!/bin/sh

if [ $# -lt 2 ] then echo "Usage $0 servername envtype" exit 1 fi

servername=$1 envtype=$2 srv=echo $servername | tr "a-z" "A-Z" srvtype=echo $envtype | tr "a-z" "A-Z" echo $srv echo $srvtype

if [ "${srv}" <> "SCP" ]; then if [" ${srv}" <> "RENTD" ]; then echo "Invalid servername" exit 1; fi fi

I am getting this error when running the shell script

  • [ 2 -lt 2 ]
  • servername=scp
  • envtype=prd
  • echo scp
  • tr a-z A-Z
  • srv=SCP
  • echo prd
  • tr a-z A-Z
  • srvtype=PRD
  • echo SCP SCP
  • echo PRD PRD
  • [ SCP ]
  • [ SCP ] /tmp/testupper.sh: 19: [ SCP: not found
1
  • Glad you found your issue. Your question formatting doesn't reflect what is code as opposed to text (eg, your actual "I am getting this error..." Could you Edit your question (from the Share Edit Follow Flag set of links? In edit mode, highlight the code and click the { } button to format it. (Really, all that does is put 4 spaces in front of each line of code, but that's all markdown needs.) See also stackoverflow.com/editing-help for other available formatting in questions and answers. And, even though you found your answer, it's still worth editing for posterity Commented Sep 9, 2022 at 15:36

1 Answer 1

1

Found my issue.

[" ${srv}" <> "RENTD" ] 

there is a space being prefixed to the srv variable, between the " and the $: " ${srv}"

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

3 Comments

Right - spaces are usually not syntactical in sh (ie, POSIX family) shells, but inside quoted strings they are always literal characters.
Also - make sure you know what sh-shell you are really using. One way is with this oneliner: which sh | xargs ls -la . That should show you where the symlink sh is really pointing.
You may accept your own answer to indicate that your issue has been resolved.

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.