bash syntax error

1

I have changed the code, now I do not execute the instruction dd

#!/bin/bash
while true
do
echo "Bienvenido al instalador de sistemas operativos en pendrive"
echo "Indica dónde está la iso a intalar"
echo "Si quires salir pulsa la tecla p "
read ruta
        if [ $ruta = "p"  ]
                then
                        exit
        elif [ -z "$ruta" ]
                then
                         echo "Oiga, introduzca la ruta"
                 elif [ -f $ruta]
                         #Aquí comprobamos que la variable ruta no esté vacía y sea la ruta exacta donde cargar la imagen del sistema operativo a instalar.
                         then
                                echo "Ahora introduce la ruta donde está el pendrive"
                                        read rutapen
                                                 if [[ ( -n "$rutapen" ) && ( -d "$rutapen" ) ]]
                                                        then
                                                                'dd if=$ruta of=$rutapen'
                                                                #Aquí ejecutamos la instrucción que permite grabar las isos booteables
                                                        else
                                                                echo "La ruta no es correcta"
                                                fi
        fi

done
    
asked by ras212 04.10.2016 в 22:26
source

2 answers

1

When you compare strings use the quotes and put the variable inside "$ ruta"

    if [ "$ruta" == "p"  ]
            then exit
    elif [ "$ruta" != "" ]

If you want to know if a string is of zero length you use:

if [ -z "$ruta" ]

another error

This:

elif [[ ( -n "$ruta" ) &&  ( -f "$ruta" ) ]]

It should be written like this:

elif [ -n "$ruta" ] &&  [ -f "$ruta" ]

Or in this other way

elif [ -n "$ruta" -a -f "$ruta" ]

In this line you have the same error as the one mentioned above:

if [[ ( -n "$rutapen" ) && ( -d "$rutapen" ) ]]

Reference (in English)     
answered by 05.10.2016 в 15:37
0

The line elif [ $ruta !="" ] It's wrong, you can not compare the strings that way. Instead, use this syntax: elif [ $ruta -eq "" ]

-eq is NOT EQUAL

    
answered by 05.10.2016 в 14:59