I have been trying to write a command (Solaris server) that adds a user to a specific group. It's a pretty long command so I'll post the whole command here and then break it down.
USER=myUser && sudo /usr/sbin/usermod -G `awk -v delim="," -F: '/[:,]'$USER'/ { groups = groups $1 delim; } END { groups = groups "myGroup"; print groups}' /etc/group` myUser
The inner awk command compiles a comma-delimited list of current groups and the outer command takes this list in the -G parameter.
Both awk and usermod are giving me syntax errors (near line 1, but there's only one line), but I have a feeling one error is caused by the other.
Are there any glaring syntax errors here that I'm missing? Could this be caused by a shell issue? As a disclaimer, I am using the && construct instead of a semicolon due to some higher-level text processing issues but that should not affect the execution, in my opinion (I have tested it).