Write an Interactive Linux Bash Script Using vim (Step-by-Step)

Опубликовано: 27 Август 2026
на канале: Sien Serey
33
0

In this video, I’ll show you how to write a powerful Bash script using vim. This script lets you type keywords like ram, cpu, net, or ip, and instantly shows live system info in color!

You’ll learn:

How to use vim to write a shell script

How to save and quit properly

How to run and test your script in Linux
Perfect for Linux beginners learning the command line and scripting.

#!/bin/bash

while true; do
read -p "Enter keyword (ram, cpu, hdd, net, time, ip): " key

([ "$key" == "ram" ] && echo -e "\e[1;31m$(free -h)\e[0m") ||
([ "$key" == "cpu" ] && echo -e "\e[1;31m$(lscpu)\e[0m") ||
([ "$key" == "hdd" ] && echo -e "\e[1;31m$(df -h)\e[0m") ||
([ "$key" == "net" ] && echo -e "\e[1;31m$(ifconfig)\e[0m") ||
([ "$key" == "time" ] && echo -e "\e[1;31m$(timedatectl)\e[0m") ||
([ "$key" == "ip" ] && echo -e "\e[1;31m$(hostname -I)\e[0m") ||
echo -e "\e[1;33mInvalid input: $key\e[0m"

echo
done