I am trying to get a variable to compare to a string, and then do something if it does and go on to the next, but when i look at it in debug mode, the variable just shows up as '' with nothing in it.
#!/bin/bash
echo -e "Enter the name of the document you wish to edit:\c"
read dname
CTYPE= file "$dname" | cut -d\ -f2
echo $CTYPE
VAR="ASCII"
VAR2="cannot"
if [ "$CTYPE" == "$VAR" ]
then
vi $dname
fi
I get this result:
+ VAR=ASCII
+ VAR2=cannot
+ '[' '' == ASCII ']'
Where the '' is empty even though I echod it and see that it is not empty.
I have tried it like these other ways as well, and get the same or similar non working result:
CTYPE= file "$dname" | cut -d\ -f2
if [ "$CTYPE" == "$VAR" ]
ctype= file "$dname" | cut -d\ -f2
if [ $ctype = "ASCII" ]
ctype= file "$dname" | cut -d\ -f2
if [ "$ctype" = "ASCII" ]
ctype= file "$dname" | cut -d\ -f2
if [ "$ctype" == "ASCII" ]
Not sure what I am missing, I've read so many posts I don't know where to go from here. Thank you!