0

Here is my script.

#!/bin/sh
grep $ `date +%Y%m%d`/filename.txt | sed 1d

pretty simple. I am looking to be able to run the script with just a value after it, where the value should replace the "$", such as:

bash-4.1$ ./script.sh | "value"

Any ideas on how I can do this?

2
  • Welcome to Stack Overflow. Please read the About page soon. The notation ./script.sh | "value" will run your script with no arguments and send the standard output to a program value. You can use ./script.sh "value" to pass value as $1 to the shell script (so you'd replace the $ with $1). If you want to search for a pipe symbol followed by 'value', then you'd need ./script.sh '| value' with the pipe inside quotes. Commented Feb 14, 2014 at 15:16
  • ...by the way, if you want a good place to start learning bash (rather than guessing at syntax), I'd suggest mywiki.wooledge.org/BashGuide Commented Feb 14, 2014 at 15:54

1 Answer 1

2

Use $1, and run it as ./yourscript value.

That is to say:

#!/bin/sh
grep -e "$1" "$(date +%Y%m%d)/filename.txt"

...and...

$ ./yourscript "value"

The pipe construct isn't appropriate here -- it's used when you connect the output of one process to the input of another.

See also http://mywiki.wooledge.org/Arguments

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.