Please use ***[code][/code]
*** tags around your code and data, to preserve the original formatting and to improve readability. Do not
use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
The command whoami
will give you the username without the extra stuff. But bash
, and probably most other modern shells will also have some preset variables for you, such as $USER
, that can give you the same info. See the man page for the full list of environment variables.
Finally though, a small warning. When you use "#!/bin/sh
" as the shebang, the system will use whatever is defined as its default POSIX interpreter, and the script will be interpreted in regards to to POSIX compliance. If you use features specific to a certain shell in such scripts (such as bash
's arrays, which are not defined in POSIX), then there's no guarantee it will work properly.
Note that undefined features like arrays may still work for you if your system's sh
interpreter actually is bash
, but many linux distros use dash
as their default sh
interpreter instead, which is a stricter POSIX based shell. dash
doesn't support arrays.
So always be sure to use the actual interpreter you're coding for in your shebang. If you're coding for bash
, make it "#!/bin/bash
". Save "#!/bin/sh
" for scripts that need to be made as portable as possible, such as those in used by init
See here for the main differences between bash and POSIX scripting: