[root@sharyng JB]# cat Jewl.sh
#!/bin/bash
echo "Welcome to the Jewelbox Script"
echo "This script performs operations and modifies file lines based on the provided mathematical operator."
echo "Operations:"
echo "+ : Add a single line to a file. You'll be prompted to enter the line content and the target file path."
echo "- : Remove a single line from a file. You'll be prompted to enter the line number and the target file path."
echo "* : Remove multiple lines from a file. You'll be prompted to enter the file path containing line numbers to remove and the target file path."
echo "/ : Add multiple lines to a file. You'll be prompted to enter the file path containing lines to add and the target file path."
echo "Please provide an operator (+, -, *, /):"
# Directly read the operator from stdin
read operator
# Function to invoke core.sh with the operator
invoke_core() {
./core.sh
}
# Execute logic based on the operator
case $operator in
+)
echo "You chose to add a line. Please enter the line content:"
read line_content
echo $line_content>>destinations.txt
;;
-)
echo "You chose to remove a line. Please enter the line content:"
read line_content
sed -i "/$line_content/d" "sed -i ~/destinations.txt"
;;
\*)
echo "You chose to remove multiple lines. Please enter the filepath containing line numbers to remove (one per line):"
read line_numbers_filepath
echo "Enter the target filepath to modify:"
read filepath
mv filepath /destinations.txt
while IFS= read -r line_number; do
sed -i "${line_number}d" "$filepath"
done < "$line_numbers_filepath"
echo "Lines removed from $filepath."
;;
/)
echo "You chose to add multiple lines. Please enter the filepath containing lines to add (one per line):"
read lines_to_add_filepath
echo "Enter the target filepath to modify:"
read filepath
mv filepath /destinations.txt
cat "$lines_to_add_filepath" >> "$filepath"
echo "Lines added to $filepath."
;;
*)
echo "Invalid operator. Please use +, -, *, or /."
exit 1
;;
esac
# Invoke core.sh with the operator after performing the action
invoke_core
not debugged
by
Tags:
Leave a Reply