Define a variable in a shell script

Yes, there are plenty of manuals on how to set variables in a script.
But I want to define a variable on script startup.
For example, I wish to display on script startup that file, which is x hours later - script.sh hours=2 . So I open the file which is with date 2 hours later.

Here is the script:

NOW=$(date -d "1 hour" '+%Y.%m.%d-%H.00.00_*.00.00.txt' )
echo "**************"
cat /air/playlists/$NOW |grep servers2

I tried it with read varname, but it's not working.
Can anybody help?

9

1 Answer

Here you have something to build on.

#!/bin/bash
a=/air/playlists
while true; do read -r -p "Hello, how many hours forward? " b b=${b:-0} if [[ ! $b =~ [0-9]+ ]]; then continue fi c=$(date -d "$b hour" "+%Y.%m.%d-%H.00.00_*.00.00.txt") echo -e $_{0..20}\\b* [[ -e $(echo $a/$c) ]] && { grep -e 'servers2' $a/$c; } || echo "Error file not found..." continue
done

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like