Linux
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
Depending on how long it is you could just post it inline with three backticks (`) before and after the code. That's markdown for a code block.
Example:
#!/bin/bash
echo "This is code block"
echo "notice everything is monospaced"
while true; do
some example of indentation
done
I guess I'll post it here then:
#!/bin/bash
# Function to display the menu
display_menu() {
echo "Select an option:"
echo "1. Move all .LRV files to 'LRV' directory"
echo "2. Undo move operation"
echo "3. Rename files starting with 'GL' to 'GX'"
echo "4. Undo renaming operation for .LRV files"
echo "5. Exit"
read -p "Enter choice (1, 2, 3, 4, or 5): " choice
}
# Function to handle option 1
move_lrv_files() {
# Create the LRV directory
mkdir "LRV"
# Move all the .LRV files to the LRV directory
mv *.LRV "LRV"
echo "Moved all .LRV files to 'LRV' directory"
}
# Function to handle option 2
undo_move_operation() {
# Move all .LRV files back to the working directory
mv LRV/*.LRV .
# Remove the LRV directory
rmdir LRV
echo "Undid move operation"
}
# Function to handle option 3
rename_files() {
# Rename files starting with 'GL' to 'GX'
for file in GL*; do
newname="${file/GL/GX}"
mv "$file" "$newname"
echo "Renamed file '$file' to '$newname'"
done
}
# Function to handle option 4
undo_rename_files() {
# Undo renaming operation for .LRV files (revert files from 'GX' to 'GL')
for file in GX*.LRV; do
newname="${file/GX/GL}"
mv "$file" "$newname"
echo "Renamed file '$file' to '$newname'"
done
}
# Main script
if [[ $1 == "-d" ]]; then
# Use directory provided as command-line argument
directory=$2
else
# Ask user for the working directory
read -p "Please enter the path of the working directory: " directory
fi
# Change the working directory and check if it was successful
if cd "$directory"; then
while true; do
display_menu
# Check user choice and execute the appropriate function
case $choice in
1)
move_lrv_files
;;
2)
undo_move_operation
;;
3)
rename_files
;;
4)
undo_rename_files
;;
5)
echo "Exiting..."
break
;;
*)
echo "Invalid choice"
;;
esac
echo
done
else
# Error message if cd command fails
echo "Error: Invalid path. Please double check the working directory."
fi
You can share on gopro communities
For single file scripts you can use gist, some online note sharing website or if it is short paste it directly in a post or comment