Hi, I'm having a little problem with bash. I have gone through a couple of tutorials online for bash, but the only real language I've ever really used before is basic.
This looks nearly to right to me (famous last words!) but it isn't working.
This is a test of what I am trying to do - I am trying to list the contents of a directory of all text files with a certain extension (in this case *.txt). What I want to do is test if the files exist, and if they do, display the first line of each file.
in $HOME/lyrics are 2 files called 1.txt and 2.txt, and the first line of each contains a name of a song as a test.
if [ ls $HOME/lyrics/*txt 1>/dev/null 2>&1 ]; then
echo "Lyrics files found:"
echo " "
for i in $HOME/lyrics/*txt; do
head -n 1 $i
echo "no text files found."
All I ever get as a result is:
[me@mymachine me]$ /bin/bash lyrics.sh
No text files found.
Can anyone please tell me what I am doing wrong with the first part of the "if" for it not to give me any results?