Что я могу использовать вместо чтения пути к файлу [закрыто]Linux

Anonymous
Что я могу использовать вместо чтения пути к файлу [закрыто]

Сообщение Anonymous »

что я могу использовать вместо чтения пути к файлу, я пробовал, чтение имени файла не помогло, путь к файлу не сработал, я попробовал все, но не могу это исправить, пожалуйста
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
}


Подробнее здесь: https://stackoverflow.com/questions/784 ... d-filepath

Вернуться в «Linux»