Problem BASH script linux

-1

Hi, I have the following problem:

  

Make a script that moves all the programs in the current directory (executable files) to the subdirectory "bin” of the HOME directory of the user currently logged in.

     

The script must print on the screen the names of those it moves, and indicate how many it has moved, or that it has not moved any.

     

If the “bin” directory does not exist, it must be created.

I would not know how to start doing it, the only thing I did was to put an instruction:

if [ !-d $1 ]; then  # Verifico si no es un directorio válido  
    echo "$1 no es un directorio válido"  
fi    
    
asked by Janzek 17.10.2018 в 20:29
source

1 answer

0

what you need is to start learning the basic unix commands before doing the script using the ls command to list the files of the directory you should also take into account if you need the hidden files ls -a and that list saved in a variable to use a for do and use the mv statement is the equivalent of windows to use the mouse to < strong> Cut

#!/usr/bin/ksh
RUTA_SCRIPT=Donde alojas tu script
RUTA_ORIGEN=ruta de donde estan los archivos
RUTA_DESTINO=ruta de donde seran pegados
cd $RUTA_ORIGEN                              #Muevete a la ruta

#Para listar lo puedes hacer de varias formas te presento dos

#En una Variable
LISTA=ls -ltr       

#En un Archivo
ls -ltr > $RUTA_SCRIPT/lista.txt

for x in 'echo $LISTA'                        #Con la variable
for x in 'cat $RUTA_SCRIPT/lista.txt'     #Con el Archivo
do
   mv $RUTA_ORIGEN/$x $RUTA_DESTINO
done

It's a matter of trying and learning for unix you just have to take care to apply the rm command

    
answered by 18.10.2018 в 14:45