4 added 1508 characters in body
source | link

Update (from our chat), I think a case statement works better for what you are trying to accomplish here:

#!/bin/bash

clear
lred='\033[1;31m'
red='\033[0;31m'
NC='\033[0m' # No Color
blue='\033[0;34m'
lblue='\033[1;34m'

# tells echo to enable backslash escapes
echo -e "${red}Welcome to Lab 7 Utilities Menu ${NC}"
sleep 3
clear
echo -e "${lblue}Choose one of the options from the following list:${NC}"
echo -e "${blue}1. Monitor existing processes ${NC}"
echo -e "${blue}2. Copy passwd to /home directory ${NC}"
echo -e "${blue}3. Ping local host ${NC}"
echo -e "${lred}4. Exit ${NC}"

read num

case $num in
        1)
           ps aux
           echo -e "${lred}The list has been successfully generated! ${NC}"
        ;;
        2)
           if [ -e "/etc/passwd" ]; then
              sudo cp /etc/passwd /home
              echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
           else
              echo "The File does not exist"
           fi
        ;;
        3)
           ping -c 4 127.0.0.1
           echo -e "${lred}You have completed pinging localhost. ${NC}"
        ;;
        4)
           clear
        ;;
        *)
           echo -e "${red}Please choose between number 1 and 4. ${NC}"
        ;;
esac


Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

Update (from our chat), I think a case statement works better for what you are trying to accomplish here:

#!/bin/bash

clear
lred='\033[1;31m'
red='\033[0;31m'
NC='\033[0m' # No Color
blue='\033[0;34m'
lblue='\033[1;34m'

# tells echo to enable backslash escapes
echo -e "${red}Welcome to Lab 7 Utilities Menu ${NC}"
sleep 3
clear
echo -e "${lblue}Choose one of the options from the following list:${NC}"
echo -e "${blue}1. Monitor existing processes ${NC}"
echo -e "${blue}2. Copy passwd to /home directory ${NC}"
echo -e "${blue}3. Ping local host ${NC}"
echo -e "${lred}4. Exit ${NC}"

read num

case $num in
        1)
           ps aux
           echo -e "${lred}The list has been successfully generated! ${NC}"
        ;;
        2)
           if [ -e "/etc/passwd" ]; then
              sudo cp /etc/passwd /home
              echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
           else
              echo "The File does not exist"
           fi
        ;;
        3)
           ping -c 4 127.0.0.1
           echo -e "${lred}You have completed pinging localhost. ${NC}"
        ;;
        4)
           clear
        ;;
        *)
           echo -e "${red}Please choose between number 1 and 4. ${NC}"
        ;;
esac


Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

3 added 108 characters in body
source | link

Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

#!/bin/bash
clear
read num
if [ "$num" -eq 2 ]; then
        if [ -e "/etc/passwd" ]]; then
           sudo cp /etc/passwd /home
           echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
        else
           echo "The directoryFile does not exist"
        fi
else
        echo "You entered a number that isn't '2'"
fi

The -d argument checks if FILE exists and is a directory. What you want is -e which checks FILE exists.

Also you were trying to pipe | after the then, which would cause more conflicts as it is incorrect for what you are trying to do.

Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

#!/bin/bash
clear
read num
if [ "$num" -eq 2 ]; then
[ -e "/etc/passwd" ]
        sudo cp /etc/passwd /home
        echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
else
        echo "The directory does not exist"
fi

The -d argument checks if FILE exists and is a directory. What you want is -e which checks FILE exists.

Also you were trying to pipe | after the then, which would cause more conflicts as it is incorrect for what you are trying to do.

Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

#!/bin/bash
clear
read num
if [ "$num" -eq 2 ]; then
        if [ -e "/etc/passwd" ]; then
           sudo cp /etc/passwd /home
           echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
        else
           echo "The File does not exist"
        fi
else
        echo "You entered a number that isn't '2'"
fi

The -d argument checks if FILE exists and is a directory. What you want is -e which checks FILE exists.

Also you were trying to pipe | after the then, which would cause more conflicts as it is incorrect for what you are trying to do.

2 added 287 characters in body
source | link

Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

#!/bin/bash
clear
read num
if [ "$num" -eq 2 ]; then
[ -e "/etc/passwd" ]
        sudo cp /etc/passwd /home
        echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
else
        echo "The directory does not exist"
fi

The -d argument checks if FILE exists and is a directory. What you want is -e which checks FILE exists.

Also you were trying to pipe | after the then, which would cause more conflicts as it is incorrect for what you are trying to do.

Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

#!/bin/bash
clear
read num
if [ "$num" -eq 2 ]; then
[ -e "/etc/passwd" ]
        sudo cp /etc/passwd /home
        echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
else
        echo "The directory does not exist"
fi

Are you sure you want to copy your passwd file to the /home directory? Other than that, this should work:

#!/bin/bash
clear
read num
if [ "$num" -eq 2 ]; then
[ -e "/etc/passwd" ]
        sudo cp /etc/passwd /home
        echo -e "${lred}The passwd file has been copied to your home directory. ${NC}"
else
        echo "The directory does not exist"
fi

The -d argument checks if FILE exists and is a directory. What you want is -e which checks FILE exists.

Also you were trying to pipe | after the then, which would cause more conflicts as it is incorrect for what you are trying to do.

1
source | link