Можно ли создать такую ​​мягкую ссылку?

Ниже проверяется, что оба файла (переданные как $1 и $2) существуют, и выполняется конкатенация $1 и $2 (я думаю, это то, что вы пытаетесь сделать). Если ни один из файлов еще не существует, пользователю будет предложено поочередно вводить имена файлов sourc и dest, пока он не введет существующие файлы - ctrl-c для выхода в противном случае!

#!/bin/bash
#Date: July 14 2016

# Use -f to test if files exist
if [[ -f "$1" ]] && [[ -f "$2" ]]; then
    echo "Appending contents of $1 to $2"
    # Use cat to take the contents of one file and append it to another
    cat "$1" >> "$2"
    echo "Contents of $2 are: "
    cat "$2"
    # Don't want to go any further so exit.
    exit
fi


# You could consider merging the logic above with that below
# so that you don't re-test both files if one of them exists, but the
# following will work.

clear
sourc=''
dest=''

while [[ ! -f "$sourc" ]]
do  
    echo -n "Enter the source file name: "
    read sourc

    if [ -f "$sourc" ]; then
        echo "The file name you entered was found!";
    else
        echo "The file name you entered was invalid - please try again";
    fi
done

while [[ ! -f "$dest" ]]
do
    echo -n "Enter the destination file name: "
    read dest

    if [ -f "$dest" ]; then
        echo "The file name you entered was found!";
    else
        echo "The file name you entered was invalid - please try again";
    fi
done

cat "$sourc" >> "$dest"
echo "Appending $sourc to $dest"
echo "Contents of $dest are: "
cat "$dest"
3
18.09.2016, 11:29
1 ответ

Теги

Похожие вопросы