I always write some magic numbers in my interactive shells and shell scripts.
For instance, If I want to list my users's names and shells, I'll write
cut --delimiter=: --fields=1,7 /etc/passwd
There exist two magic-numbers 1
,7
. And there are more and more magic-numbers in other circumstances.
Question
How to avoid magic-numbers in interactive shells and shell scripts?
Supplementary background
Our teacher told us using cut -d: -f1,7 /etc/passwd
. But for new linux-users, they don't konw what's meaning of d
,f
,1
,7
.(not just for new linux-users,the whole system has so many configuration files that it is not easy for a person to remember every magic-numbers)
So, in interactive shells, we can use --delimiter
, --fields
,and the bash repl(or zsh,fish) has good tab completion to it.
How about the 1
and 7
? In shell scripts, It's a good method to declare some const variables like LoginField=1 and ShellField=7 after reading the man 5 passwd
. But when some one is writing in the interactive shells, it's not a good idea to open a new window and search the constants of LoginField=1
,ShellField=7
and define it. how to using some thing like tab completion to simplify operations?