I am creating a script that checks to see if the first character in the second line of an output file is " " (blank or not). If it is blank I want to echo 'yes' if not echo 'no'. I am trying this at the moment. the test file contains the following:
###############
#
# #############
# #
# ######### # #
# # # #
# ### ##### # #
# # # # #
# # ###########
# #
###############
and my code is:
#!/bin/bash
line2=$(awk 'NR==2 {print; exit}' < test)
blank_check="${line2:0:1}"
if [ "blank_check" == " " ];
then
echo "yes"
else
echo "no"
fi
the problem seems ot be in the line line2=$(awk 'NR==2 {print; exit}' < test)
as this gets rid of all the blanks spaces and the line2 end up equal to "#" instead of " "
are there any other better ways I can test if the first character of the second line is " "?
if
have a$
?if [ "$blank_check" == " " ];
– Apr 11 '21 at 07:00