Expansion not working properly

I'm using an Ubuntu machine and expansion is not working properly. What would cause this? Do I need to check for any particular bash packages?

$ ipcs -m | grep $USER | awk '{printf "%s ",$2}'


$ ipcs -m | grep UNF | awk '{printf "%s ",$2}'
294912 1048577 425986 688131 786436 1245189 917510 1015815 1146888 1277961 1409034 1441803 1540108 2359309 2424846 2555920

A ridiculously basic example with expansion not working.

ps -ef | grep $USER

USER is generally exported on login but is not read-only -- something could conceivably have changed or unset it before you get to that point. That would be far more likely than expansion being "broken".

Show what this prints:

printf "[%s]\n" $USER

What's the result of env | grep USER (Just the word USER)
What's the result of echo "[$USER]"

You mean shell's "parameter and variable expansion"? Are you sure USER is defined? What's the result of echo $USER ?

You know you don't need grep if awk is around?

$ printf "[%s]\n" $USER 
[UNF\1122]
$ env | grep USER
USER=UNF\1122
$ echo "[$USER]"
[UNF\1122]

I'm guessing its getting confused by the \. When I did this it matched every character in my username.

$ ps -ef | grep "[$USER]"
$ echo $USER
UNF\1122

grep did not match any "UNF\1122" in the ps output because none of the ps output contained "UNF\1122".

I am not sure what \1122 is supposed to be, but it's some unicode character you may not have noticed because it's probably unprintable in your terminal.

Make sure that it's not actually in your user name:

awk -v U="$UID" -F":" '$3 == U { print $1 }' /etc/passwd | hexdump -C

This isn't Cygwin, is it?

You said you were in an Ubuntu box. The env USER should be set to just the name of the account you're logged in. Somewhat, it has been set to that "UNF\1122", unless that that's the name of the account.

Check what's the user name:

grep UNF /etc/passwd | od -bc

Log out and log in again and check once more for env

With this it matched the "U" "N" "F" "\" "1" "2" "2" "2". As individual characters. I have my color on in grep.

$ ps -ef | grep "[$USER]"

These are NOT "\1122" trailing characters. My username is "UNF\1122". Don't ask me why. That is what the administrator felt like doing.

That awk command is not giving any output.

I am using Ubuntu.

"UNF\1122" IS my username.

The way the admin setup the accounts is weird. My username is not in /etc/passwd file.

That's a bit short-sighted from the part of who decided to have that scheme of username. The `\' is special to the shell. It is used as the escape character. That's why the original command would not work:

If USER="UNF\\\\1122" or USER='UNF\\1122' , then that command might work

Or maybe

ipcs -m | awk -v user="${USER%\\\\*}" '$0 ~ user {printf "%s ", $2}'

What be the output of

 /bin/ps -ouser

?

Really?

That's the file awk was looking at. It must be there.

I'm surprised he was able to put that in a username, really. From man useradd:

       Usernames must start with a lower case letter or an underscore,
       followed by lower case letters, digits, underscores, or dashes. They
       can end with a dollar sign. In regular expression terms:
       [a-z_][a-z0-9_-]*[$]?

This is probably a user created from a LDAP, therefore it will not be a local user in /etc/passwd .

Except he told me the command I gave him, which worked, printed a user from /etc/password :wall:

Are you talking about this?

awk -v U="$UID" -F":" '$3 == U { print $1 }' /etc/passwd | hexdump -C

This is what I said? Sorry if I was confusing.

These don't seem to be working :(.

Would you mind to answer this question that was posted previously?