From 5aea4ade56d9a33507675c42998b9a225ec0165c Mon Sep 17 00:00:00 2001 From: medusa Date: Sat, 27 Apr 2024 02:52:41 +0000 Subject: [PATCH] Add docs/tech_docs/linux/rename.md --- docs/tech_docs/linux/rename.md | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 docs/tech_docs/linux/rename.md diff --git a/docs/tech_docs/linux/rename.md b/docs/tech_docs/linux/rename.md new file mode 100644 index 0000000..b3c3b7f --- /dev/null +++ b/docs/tech_docs/linux/rename.md @@ -0,0 +1,72 @@ +To convert the recipe name "Slow Cooker Smoky BBQ Chicken Drumsticks" into a more script-friendly format like "Slow_Cooker_Smoky_BBQ_Chicken_Drumsticks", you can use a simple Bash command to replace spaces with underscores. This is a common task when you need to generate filenames or identifiers that require non-spaced strings. + +Here’s a straightforward way to do this in Bash, which you can use repeatedly: + +### Bash Script + +Create a script named `format_recipe_name.sh` with the following content: + +```bash +#!/bin/bash + +# This script converts a recipe name with spaces into a format with underscores + +# Input: Recipe name as a string +# Output: Formatted recipe name with underscores + +# Function to replace spaces with underscores +convert_name() { + echo "$1" | sed 's/ /_/g' +} + +# Example usage: +recipe_name="Slow Cooker Smoky BBQ Chicken Drumsticks" +formatted_name=$(convert_name "$recipe_name") +echo "Formatted Recipe Name: $formatted_name" +``` + +### How to Use the Script + +1. **Make the Script Executable:** + Open your terminal and run the following command to make your script executable: + ```bash + chmod +x format_recipe_name.sh + ``` + +2. **Run the Script:** + You can now run the script by typing: + ```bash + ./format_recipe_name.sh + ``` + This will output the formatted name: `Slow_Cooker_Smoky_BBQ_Chicken_Drumsticks`. + +### Modifying the Script for General Use + +If you want to use the script for any recipe name, you can modify it to accept an input argument: + +```bash +#!/bin/bash + +# Function to replace spaces with underscores +convert_name() { + echo "$1" | sed 's/ /_/g' +} + +# Check if an argument is provided +if [ $# -eq 0 ]; then + echo "Usage: $0 'recipe name'" + exit 1 +fi + +# Convert and output the formatted name +formatted_name=$(convert_name "$1") +echo "Formatted Recipe Name: $formatted_name" +``` + +Now, you can pass any recipe name as an argument to the script: + +```bash +./format_recipe_name.sh "Slow Cooker Smoky BBQ Chicken Drumsticks" +``` + +This flexible script can handle any name you provide, making it easy and repeatable for different recipes or other similar formatting needs. \ No newline at end of file