Simple command for showing comments on shell script

Suppose you have the following script:

# My comment line 1
# My comment line 2
# My comment line 3

echo "My script"
cd $MY_PATH
./anotherScript.ksh

Is there any command to show:

# My comment line 1
# My comment line 2
# My comment line 3

Alternatively, I could write a script to detect the first block of comments.

Thanks

Upvotes: 0

Views: 9537

Answers (3)

noel
noel

Reputation: 2339

This will output your file to the grep command which will print each line with a "#"

echo "My script" | grep "#"

EDIT I'M DUMB

all you need to do is grep '#' file if I'm understanding correctly this time.

Upvotes: -1

rockerest
rockerest

Reputation: 10508

You could cat script.sh | grep ^\# to only show those lines.

Upvotes: 0

user529758
user529758

Reputation:

Try this:

grep '^\#.*$' myscript.sh

Upvotes: 5

Related Questions