1

lets say when I execute command and then grep it for a specific output.

for example: man cat|grep "Written"

This gives the name of the authors.

My problem is I want to do this via read.

here is an example of my script:

#!/bin/bash read variable #lets say input is: man cat|grep "Written" $variable 

It does not seem to work. I need this to work as I am doing a larger script and this part got me stuck. Any tips are appreciated.

3
  • var=$(man cat | grep 'Written') later you use it like: "$var" (don't forget double quotes to avoid word splitting).
    – thanasisp
    CommentedMay 14, 2022 at 2:01
  • "It does not seem to work" -- exactly how are you invoking your script? What actually happens? How does that differ from what you expect?CommentedMay 14, 2022 at 2:09
  • But, before you use eval (or bash -c),  think hard about why you want to do this, or why you believe that you need to.CommentedMay 20, 2022 at 19:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.