I have a bunch of bash files, and each have a function and a comment block that describes that function.Example:~/helpers/plugins/test-util.bash# Function Name: test_util## Description: .....function test() ....I have a help function that will be triggered when i pass --help parameter my function. The help is specific for each function name.Function names contain _ in them, while the filenames have - instead.Example: test-util.bash is the filename while the function that will be passed will be called test_utilThe command i execute looks like:helpers test_util --helpThis will execute the test_util function in the location ~/helpers/plugins/test-util.bashQuestion:I want to dynamically show the comments attached in each file. What i do is:1- Construct the correct file name from the passed function name using FILENAME= echo ~/helpers/plugins/${1}.bash | tr '_' '-' to replace any underscores2- I extract the comments using cat $FILENAME | grep '#' | cut -c 2- | tail -n +3Now, my problem is with the cat statement as i am passing the filename as a variable that i pass to the function and i dont seem to get this working.The command works fine in terminal if i am passing the filename directly to the cat command.Thanks for any help
Dynamically extract comments from files using cat
shell;grep;cat
If your assignment really isFILENAME= echo ~/helpers/plugins/${1}.bash | tr '_' '-'as it appears in the question, then this is incorrect. The correct form isFILENAME=$(echo ~/helpers/plugins/${1}.bash | tr '_' '-')The command as it appears in the question means to run echo ... | tr ... with an empty variable named FILENAME in the environment.