bash y/n

Sekcia: Aplikácie & Desktop 25.10.2012 | 09:16
Avatar Ivan Centos 6.x  Používateľ
Dobry den,

rad by som podmienil spustanie jednotlivych krokov v shell scripte "Y/N" potvrdenim. Viete mi prosim poradit ako upravit tento script aby pri "Y" zbehol prikaz, a pri "N" skoncil?
Dakujem.


#!bin/bash

# Must run as root
if [ $(whoami) != "root" ]; then
echo "You need to run this script as root."
echo "Use 'sudo ./$script_name' then enter your password when prompted."

else
read -p "Continue (Y/N):"
[ "REPLY" =="Y" ] || vytvorenie "xz" suboru
[ "REPLY" !="Y" ] || die
    • Re: bash y/n 25.10.2012 | 11:00
      asdf   Návštevník
      v bashi je na to prikaz "select"

      http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_06.html
    • Re: bash y/n 29.10.2012 | 22:24
      d_   Návštevník
      #!bin/bash
      
      # Must run as root 
      if [ $(whoami) != "d_" ]; then
      	echo "You need to run this script as root."
      	echo "Use 'sudo ./$script_name' then enter your password when prompted."
      else
      	read -p "Continue (Y/n):"
      
      	if [ "REPLY" == "Y" ] || [ ! -z REPLY ]; then
      		# create file
      		echo "ahoj root"
      	else
      		#inac
      		echo "bye no-root"
      	fi
      fi
      
      • Re: bash y/n 29.10.2012 | 22:34
        d_   Návštevník
        ups, prepac, toto je spravne
        #!bin/bash
        
        # Must run as root 
        if [ $(whoami) != "root" ]; then
        	echo "You need to run this script as root."
        	echo "Use 'sudo ./$script_name' then enter your password when prompted."
        else
        	read -p "Continue (Y/n):"
        
        	if [ "$REPLY" = "Y" ] || [ -z $REPLY ]; then
        		# create file
        		echo "ahoj root"
        	else
        		#inac
        		echo "bye ne-root"
        	fi
        	echo 
        fi