1

I am able to successfully run

/opt/hbase/hbase_current/bin/hbase

on the command line, when connected to a GNU/Linux cluster.

However, when I put this command as a line of a bash script, the error is:

: No such file or directoryopt/hbase/hbase_current/bin/hbase

What am I doing wrong?

When I added a header to the bash script based on the results of "which bash", I get the following error:

bash: ./file.sh: /bin/bash^M: bad interpreter: No such file or directory

The contents of the file are as follows:

#!/bin/bash
ENTITY="'A.B.C'"
HBASE_SHELL="/opt/hbase/hbase_current/bin/hbase"
FILE="A.B.C.txt"
/opt/hbase/hbase_current/bin/hbase
#echo "scan $ENTITY" | $HBASE_SHELL > $FILE
0

2 Answers 2

2

Oh, you have DOS-style CR/LF at the end of your lines. You can see them as they show up as ^M

Do this:

tr -d '\r' < file.sh > newfile.sh
chmod +x newfile.sh
./newfile.sh

The tr command is started with -d which means delete all occurrences of whatever follows, which in this case is the sequence representing Carriage Return (CR).

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

1 Comment

@La-comadreja Also check out the bash tag wiki. This is troubleshooting step #1.
1

It seems you have copied the script from a Windows box. Try dos2unix on the file to remove the Windows line endings:

$ dos2unix file.sh

(sudo apt-get install dos2unix if you don't have it)

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.