General
cancel
Showing results for 
Search instead for 
Did you mean: 

Simple script but can't get it to work

SOLVED
Go to solution
Charles Holland
Trusted Contributor

Simple script but can't get it to work

This is the entire script

#!/bin/bash
#/usr/bin/perl -e 'print "Changetime:".localtime((stat("$1"))[9])'

I simply want to type in the name and feed it a path and file neme for it to report on. If you harde code the $1 with a file name it works fine. Should you enter "# script /tmp/thisfile" it doesn't do the substituion and returns

Changetime:Wed Dec 31 19:00:00 1969

which is not correct.

Quick points!
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein
4 REPLIES
Sergejs Svitnevs
Honored Contributor
Solution

Re: Simple script but can't get it to work

#!/bin/bash
ENV_TEST="$1"; export ENV_TEST;
/usr/bin/perl -e 'print "Changetime:".localtime((stat("$ENV{ENV_TEST}"))[9])'


Regards
Charles Holland
Trusted Contributor

Re: Simple script but can't get it to work

Sergejs thanks for the reply. This is my first attempt at working in the bash shell.

From your reply it looks like you have to set it up as an environment variable before you can feed it to the script? I am presuming that the $ENV is some type of command that examines the environment, it then finds the variable set, and I have just fed the variable what I want it to look for so it does the substitution.

Is that anywhere correct? Isn't that like going around the corner to enter the door you're standing in front of?
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein
Sergejs Svitnevs
Honored Contributor

Re: Simple script but can't get it to work

Trying to enter the door with new script (special edition for Charles):

#!/bin/bash
/usr/bin/perl -e 'print "Changetime:".localtime((stat("$ARGV[0]"))[9])' $1

Regards
Charles Holland
Trusted Contributor

Re: Simple script but can't get it to work

Thanks for your help. First script worked fine. It just seemed that it was going the long way around to get something done.

Thanks again
"Not everything that can be counted counts, and not everything that counts can be counted" A. Einstein