我可以用什么来代替读取文件路径

问题描述 投票:0回答:1

我可以使用什么来代替读取文件路径我尝试读取文件名不起作用文件路径不起作用我尝试了所有方法但无法修复请

Function to Edit an existing file
edit_existing_file() {
    echo "Enter the full path or name of the file to edit:"
    read filepath
    if [ -f "$filepath" ]; then
        # Display file contents with line numbers
        nl "$filepath"
        cat > "$filepath.tmp"  # Create temporary file to store new text
        mv "$filepath.tmp" "$filepath"  # Replace original file with the one containing new text
        echo "File edited."
    else
        echo "File not found."
    fi
}


# Function to Edit an existing file
edit_existing_file() {
    echo "Enter the name of the file or the full file path to edit:"
    read filename
    if [ -f "$filename" ]; then
        # Display file contents with line numbers
        nl "$filename"
        echo "Enter the new content below. Press Ctrl+D when finished:"
        cat > "$filename.tmp"  # Create temporary file to store new text
        mv "$filename.tmp" "$filename"  # Replace original file with the one containing new text
        echo "File edited."
    else
        echo "File not found."
    fi
}
linux bash shell
1个回答
0
投票

已修复:) edit_existing_file() { echo“输入要编辑的文件的文件名或文件路径:” 读取文件名路径 if [ -f "$filenamepath" ];然后 行数=$(wc -l < "$filenamepath") page_size=$(tput lines) current_line=1 edited_text=$(<"$filenamepath") while true; do

© www.soinside.com 2019 - 2024. All rights reserved.