The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: stack problem
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 04-02-2002
Jimbo
Guest
 

Posts: n/a
Quote:
I understand this will return the final character of the $file variable.
Just to be clear, we are talking about returning the first or final character of a file, and does not matter if it is referenced by actual name or the filename is contained in a variable. Returning portions of what is currently held in a variable is very common, but I think not what we want here.

OK, so head -1 myfile gets you the first line. Now pipe that into a command that will cut the first column out. But if the first line is empty, this solution results in null:
Code:
char1=`head -1 myfile | cut -c1`
echo "first character is $char1"