面试题答案
一键面试#!/bin/bash
append_file_content() {
local file1="$1"
local file2="$2"
if [ ! -f "$file1" ]; then
echo "Error: The first file $file1 does not exist."
return 1
fi
if [ ! -f "$file2" ]; then
echo "Error: The second file $file2 does not exist."
return 1
fi
cat "$file1" >> "$file2"
if [ $? -eq 0 ]; then
echo "Content of $file1 has been successfully appended to $file2."
else
echo "Error occurred while appending content."
return 1
fi
}
# 示例调用
append_file_content "file1.txt" "file2.txt"