Skip to main content
se eliminaron 4 caracteres en el cuerpo
Origen Enlace
Cuauhtli
  • 8.4k
  • 1
  • 14
  • 26

Resuelto:

#!/usr/bin/env bash

declare args=$*
readonly cwd="$(pwd)"

readonly src_dir="$1"
readonly dest_dir="$2"

if [ $# -ne 2 ]; then
    echo "No se han pasado dos argumentos."
    exit 1
fi

echo "Verificando si los directorios son accesibles"
for arg in ${args}; do
    if [ ! -d "${cwd}/${arg}" ]; then
        echo "El argumento \"$arg\" no es un directorio accesible"
        exit 1
    fi
done

echo "Revisando contenido de cada directorio"
readonly content_first_dir="$(ls -p "${cwd}/${src_dir}" | grep -v /)"
readonly content_second_dir="$(ls -p "${cwd}/${dest_dir}" | grep -v /)"

echo "Copiando contenido unico"
declare -i elements_in_both=0
for element_in_first_dir in "$${content_first_dir[@]}";; do
    for element_in_second_dir in "$${content_second_dir[@]}";; do   
        [ "$element_in_first_dir" == "$element_in_second_dir" ] && ((elements_in_both++))
    done
    
    if [ "$elements_in_both" -eq 0 ]; then
        cp "${cwd}/${src_dir}/${element_in_first_dir}" "${cwd}/${dest_dir}"
    fi
    elements_in_both=0
done

Resuelto:

#!/usr/bin/env bash

declare args=$*
readonly cwd="$(pwd)"

readonly src_dir="$1"
readonly dest_dir="$2"

if [ $# -ne 2 ]; then
    echo "No se han pasado dos argumentos."
    exit 1
fi

echo "Verificando si los directorios son accesibles"
for arg in ${args}; do
    if [ ! -d "${cwd}/${arg}" ]; then
        echo "El argumento \"$arg\" no es un directorio accesible"
        exit 1
    fi
done

echo "Revisando contenido de cada directorio"
readonly content_first_dir="$(ls -p "${cwd}/${src_dir}" | grep -v /)"
readonly content_second_dir="$(ls -p "${cwd}/${dest_dir}" | grep -v /)"

echo "Copiando contenido unico"
declare -i elements_in_both=0
for element_in_first_dir in "${content_first_dir[@]}"; do
    for element_in_second_dir in "${content_second_dir[@]}"; do 
        [ "$element_in_first_dir" == "$element_in_second_dir" ] && ((elements_in_both++))
    done
    
    if [ "$elements_in_both" -eq 0 ]; then
        cp "${cwd}/${src_dir}/${element_in_first_dir}" "${cwd}/${dest_dir}"
    fi
    elements_in_both=0
done

Resuelto:

#!/usr/bin/env bash

declare args=$*
readonly cwd="$(pwd)"

readonly src_dir="$1"
readonly dest_dir="$2"

if [ $# -ne 2 ]; then
    echo "No se han pasado dos argumentos."
    exit 1
fi

echo "Verificando si los directorios son accesibles"
for arg in ${args}; do
    if [ ! -d "${cwd}/${arg}" ]; then
        echo "El argumento \"$arg\" no es un directorio accesible"
        exit 1
    fi
done

echo "Revisando contenido de cada directorio"
readonly content_first_dir="$(ls -p "${cwd}/${src_dir}" | grep -v /)"
readonly content_second_dir="$(ls -p "${cwd}/${dest_dir}" | grep -v /)"

echo "Copiando contenido unico"
declare -i elements_in_both=0
for element_in_first_dir in ${content_first_dir[@]}; do
    for element_in_second_dir in ${content_second_dir[@]}; do   
        [ "$element_in_first_dir" == "$element_in_second_dir" ] && ((elements_in_both++))
    done
    
    if [ "$elements_in_both" -eq 0 ]; then
        cp "${cwd}/${src_dir}/${element_in_first_dir}" "${cwd}/${dest_dir}"
    fi
    elements_in_both=0
done
se añadieron 426 caracteres en el cuerpo
Origen Enlace
Cuauhtli
  • 8.4k
  • 1
  • 14
  • 26
#!/bin/bash

arg=${*}
dire=`pwd`

if [ ${#} -ne 2 ]
then
    echo "No se han pasado dos argumentos."
    exit 1
else
    for a in ${arg}
    do
        if [ ! -d $dire/${a} ]
        then
            echo "El argumento $a no es un directorio accesible"
            exit 1
        fi
        
    done
    
    cd $dire/${1}
    str1=( $(ls -p | grep -v /) )
    cd $dire/${2}
    str2=( $(ls -p | grep -v /) )
    cont=0

    for i in "${str1[@]}"
    do
        for e in "${str2[@]}"
        do  
            if [ $i == $e ]
            then
                cont=$((cont+1))
            fi
        done
        
        if [ $cont -eq 0 ]
        then
            cd $dire/${1}
            cp $i $dire/${2}
        fi
        cont=0
    done
fi
#!/usr/bin/env bash

declare args=$*
readonly cwd="$(pwd)"

readonly src_dir="$1"
readonly dest_dir="$2"

if [ $# -ne 2 ]; then
    echo "No se han pasado dos argumentos."
    exit 1
fi

echo "Verificando si los directorios son accesibles"
for arg in ${args}; do
    if [ ! -d "${cwd}/${arg}" ]; then
        echo "El argumento \"$arg\" no es un directorio accesible"
        exit 1
    fi
done

echo "Revisando contenido de cada directorio"
readonly content_first_dir="$(ls -p "${cwd}/${src_dir}" | grep -v /)"
readonly content_second_dir="$(ls -p "${cwd}/${dest_dir}" | grep -v /)"

echo "Copiando contenido unico"
declare -i elements_in_both=0
for element_in_first_dir in "${content_first_dir[@]}"; do
    for element_in_second_dir in "${content_second_dir[@]}"; do 
        [ "$element_in_first_dir" == "$element_in_second_dir" ] && ((elements_in_both++))
    done
    
    if [ "$elements_in_both" -eq 0 ]; then
        cp "${cwd}/${src_dir}/${element_in_first_dir}" "${cwd}/${dest_dir}"
    fi
    elements_in_both=0
done
#!/bin/bash

arg=${*}
dire=`pwd`

if [ ${#} -ne 2 ]
then
    echo "No se han pasado dos argumentos."
    exit 1
else
    for a in ${arg}
    do
        if [ ! -d $dire/${a} ]
        then
            echo "El argumento $a no es un directorio accesible"
            exit 1
        fi
        
    done
    
    cd $dire/${1}
    str1=( $(ls -p | grep -v /) )
    cd $dire/${2}
    str2=( $(ls -p | grep -v /) )
    cont=0

    for i in "${str1[@]}"
    do
        for e in "${str2[@]}"
        do  
            if [ $i == $e ]
            then
                cont=$((cont+1))
            fi
        done
        
        if [ $cont -eq 0 ]
        then
            cd $dire/${1}
            cp $i $dire/${2}
        fi
        cont=0
    done
fi
#!/usr/bin/env bash

declare args=$*
readonly cwd="$(pwd)"

readonly src_dir="$1"
readonly dest_dir="$2"

if [ $# -ne 2 ]; then
    echo "No se han pasado dos argumentos."
    exit 1
fi

echo "Verificando si los directorios son accesibles"
for arg in ${args}; do
    if [ ! -d "${cwd}/${arg}" ]; then
        echo "El argumento \"$arg\" no es un directorio accesible"
        exit 1
    fi
done

echo "Revisando contenido de cada directorio"
readonly content_first_dir="$(ls -p "${cwd}/${src_dir}" | grep -v /)"
readonly content_second_dir="$(ls -p "${cwd}/${dest_dir}" | grep -v /)"

echo "Copiando contenido unico"
declare -i elements_in_both=0
for element_in_first_dir in "${content_first_dir[@]}"; do
    for element_in_second_dir in "${content_second_dir[@]}"; do 
        [ "$element_in_first_dir" == "$element_in_second_dir" ] && ((elements_in_both++))
    done
    
    if [ "$elements_in_both" -eq 0 ]; then
        cp "${cwd}/${src_dir}/${element_in_first_dir}" "${cwd}/${dest_dir}"
    fi
    elements_in_both=0
done
Origen Enlace
Rami
  • 1
  • 1
  • 2

Resuelto:

#!/bin/bash

arg=${*}
dire=`pwd`

if [ ${#} -ne 2 ]
then
    echo "No se han pasado dos argumentos."
    exit 1
else
    for a in ${arg}
    do
        if [ ! -d $dire/${a} ]
        then
            echo "El argumento $a no es un directorio accesible"
            exit 1
        fi
        
    done
    
    cd $dire/${1}
    str1=( $(ls -p | grep -v /) )
    cd $dire/${2}
    str2=( $(ls -p | grep -v /) )
    cont=0

    for i in "${str1[@]}"
    do
        for e in "${str2[@]}"
        do  
            if [ $i == $e ]
            then
                cont=$((cont+1))
            fi
        done
        
        if [ $cont -eq 0 ]
        then
            cd $dire/${1}
            cp $i $dire/${2}
        fi
        cont=0
    done
fi