Skip to content

Commit 3fb6ecf

Browse files
authored
feat: global alias that displays user's IPv4 address
1 parent bc0337a commit 3fb6ecf

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

Bash/displayMyIPAddress.sh

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
#!/usr/bin/env bash
2-
# A Bash script (soon to be a command) that displays my IP address
3-
# This script works on Ubuntu Linux
4-
#
5-
# Installing the necessary packages
6-
sudo apt install net-tools
7-
# Store the username in a variable
8-
user=$(whoami)
9-
# A variable that stores my IP address
10-
myIPAddress=$(ifconfig | grep "netmask" | awk '{print $2}' | grep -v "127.0.0.1" | head -n 1)
11-
echo ""
12-
echo ""
13-
echo "Displaying your IP address"
14-
sleep 2.5
15-
echo "Dear $user, your IP address is: $myIPAddress"
16-
sleep 1.25
17-
echo ""
18-
echo ""
2+
# echo ""
3+
# This Bash script creates a global alias to display my IP address, regardless of my machine
4+
echo "" >> ~/.bashrc
5+
echo "" >> ~/.bashrc
6+
echo "" >> ~/.bashrc
7+
echo "# ======= My Created Aliases =======" >> ~/.bashrc
8+
echo "#" >> ~/.bashrc
9+
echo "# This Alias displays my IP Address with just a command: displayMyIPAddress" >> ~/.bashrc
10+
# echo 'alias displayMyIPAddress="echo \$(ifconfig | grep 'netmask' | awk '{print \$2}' | grep -v '127.0.0.1' | head -n 1)"' >> ~/.bashrc
11+
echo "alias displayMyIPAddress=\"echo Your IPv4 Address is \$(ifconfig | grep netmask | awk '{print \$2}' | grep -v 127.0.0.1 | head -n 1)\"" >> ~/.bashrc
12+
echo "Done!"
13+
sleep 3
14+
echo "Do run this command:"
15+
echo "sudo source ~/.bashrc"
16+
echo "After doing that, run this command, to display your IP address: displayMyIPAddress"

0 commit comments

Comments
 (0)