I am really new with bash, but this is one of the subjects at school. One exercise was:
Give the line number of the file "/ etc / passwd", where is the information about your own login.
Assuming USERNAME
is my own login ID, I was able to do this completely like this:
cat /etc/passwd -n | grep USERNAME | cut -f1
Which just gave the required line number (there might be a more optimized way). However, I wondered if there was a way to make the command more general so that it uses the whoami
output to represent the grep template, without scripting or using a variable . In other words, to make it easy to read with a single-line command, for example:
cat /etc/passwd -n | grep (whoami) | cut -f1
Sorry if this is really a noob question.
source share