🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › linux / unix shell script: get current user name
Linux / Unix Shell Script: Get Current User Name - nixCraft
November 6, 2021 - We can use the who command as follows to print the current user account: who whoami OR use the id command: id -u -n
🌐
PhoenixNAP
phoenixnap.com › home › kb › networking › whoami linux command: examples and alternatives
whoami Linux Command: Examples and Alternatives
December 19, 2025 - The whoami command is a part of the GNU coreutils project. The command allows Linux users to see who is currently logged in. The output displays the effective username in the current shell.
🌐
Linux Hint
linuxhint.com › print_logged_in_user_names_linux
How to Print the Usernames of Currently Logged-In Users in Linux – Linux Hint
Practical tutorial on how to print the usernames of currently logged-in users in Linux using the "who", "w", "last", "finger", "users", and “whoami" commands.
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › linux / unix: logname command examples to display loginname
Linux / Unix: logname Command Examples To Display Loginname - nixCraft
November 8, 2024 - Bye."; exit 1; } exit 0 · The ... as follows to show user’s login name: echo "Hi, $USER! Let us be friends." echo "Hello, $LOGNAME!...
🌐
LinuxTeck
linuxteck.com › bash-script-hello-world
Bash Script Hello World – Step by Step Guide for Beginners
April 28, 2026 - #!/bin/bash # hello.sh - My first shell script echo "Hello, World!" echo "Today is: $(date)" echo "Logged in as: $USER" ... The $(date) syntax is called command substitution. It runs the date command inside your echo statement and inserts the ...
🌐
LinuxVox
linuxvox.com › blog › linux-get-current-username
Linux: Getting the Current Username — linuxvox.com
For example, if for some reason the whoami command fails, you should have a fallback mechanism. #!/bin/bash username=$(whoami 2>/dev/null) if [ -z "$username" ]; then username="unknown" fi echo "Hello, $username!"
🌐
Baeldung
baeldung.com › home › scripting › identify user in a bash script called by sudo
Identify User in a Bash Script Called by sudo | Baeldung on Linux
March 18, 2024 - kent$ ./get_user.sh Get the current login user by reading the $USER variable: kent Get the current login user by the whoami command: kent · As we expected, both echo commands print kent as the current login user.
Find elsewhere
🌐
Baeldung
baeldung.com › home › administration › user administration › get the current user in linux
Get the Current User in Linux | Baeldung on Linux
March 18, 2024 - As the example above shows, if our script reads $USER to get the current user, the user can easily cheat the script by changing the $USER variable. The whoami command prints the effective username of the current user when invoked:
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › hello world bash shell script
Hello World Bash Shell Script - nixCraft
June 29, 2024 - #!/bin/bash # Usage: Hello World Bash Shell Script Using Variables # Author: Vivek Gite # ------------------------------------------------- # Define bash shell variable called var # Avoid spaces around the assignment operator (=) var="Hello World" # print it echo "$var" # Another way of printing it printf "%s\n" "$var" Run it as follows: $ chmod +x update-hello.sh $ ./update-hello.sh Where, First line of the script (#!/bin/bash) is shebang. It tells the Linux/Unix how to run the script. Each shell comments start with #. Declaring a variable: Variable_Name="Values_here". Next create a program named hello2.sh to display current date and computer/system name as follows:
🌐
Linux Handbook
linuxhandbook.com › current-user-info
How to Find Current User Account in Linux
December 22, 2023 - #!/bin/bash # Get the current user account using who and awk current_user=$(who | awk '{print $1}') echo "The current user is: $current_user"
🌐
Baeldung
baeldung.com › home › administration › user administration › running script or command as another user in linux
Running Script or Command as Another User in Linux | Baeldung on Linux
November 17, 2020 - In the script, we first obtain the username with the whoami command. This will capture the username of the user executing the script. Then, we use process substitution to combine the username with the message to be printed.
🌐
GeeksforGeeks
geeksforgeeks.org › shell-scripts-to-find-how-many-users-are-logged-in
Shell Scripts to Find How Many Users are Logged In | GeeksforGeeks
April 7, 2025 - This is the only user logged in currently. To show who is logged-in. The who command lists the users with id and the time and date of user login. -a, --all same as –b, -d, --login, -p, -r, -t, -T, -u -b, --boot time of last system boot -d, --dead print dead processes -H, --heading print line of column headings -l, --login print system login processes --lookup attempt to canonicalize hostnames via DNS -m only hostname and user associated with stdin -p, --process print active processes spawned by init -q, --count all login names and number of users logged in
🌐
University of Utah
math.utah.edu › docs › info › sh-utils_8.html
GNU shell utilities - User information
This section describes commands that print user-related information: logins, groups, and so forth · id prints information about the given user, or the process running it if no user is specified
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › username-command-in-linux-with-examples
username Command in Linux With Examples - GeeksforGeeks
December 7, 2025 - Type whoami in your terminal. This simple command instantly displays the username of the effective user currently running the shell. ... id: This command basically prints the information of real and effective user or in other words the current user.
🌐
LabEx
labex.io › tutorials › linux-hello-bash-388809
Your First Bash Script: Hello World in Shell | LabEx
This lab will guide you through creating a simple shell script that prints the classic "Hello, World!" message. You will learn the fundamentals of shell programming using the Bash shell, which is widely used in Unix-like operating systems such as Linux.
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › shell-script-examples
30+ Common Linux Shell Script Examples - GeeksforGeeks
June 6, 2026 - #!/bin/bash # Prompt the user to enter their name echo "Enter your name:" # Read user input and store it in the variable 'name' read name # Display a greeting message using the stored input echo "Hello, $name! Nice to meet you." read name: Takes input from the user and stores it in the variable name. $name: Retrieves the value stored in the variable and prints it on the screen.
🌐
freeCodeCamp
freecodecamp.org › news › bash-scripting-tutorial-linux-shell-script-and-command-line-for-beginners
Bash Scripting Tutorial – Linux Shell Script and Command Line for Beginners
March 20, 2023 - We can read the user input using the read command. #!/bin/bash echo "What's your name?" read entered_name echo -e "\nWelcome to bash tutorial" $entered_name ... This code reads each line from a file named input.txt and prints it to the terminal.