Quantcast
Channel: User Peter - Reinstate Monica - Stack Overflow
Viewing all articles
Browse latest Browse all 223

Answer by Peter - Reinstate Monica for How do I spoof the current date when running a bash script?

$
0
0

I think, as I said in comments, that Cole's suggestion to shadow /bin/date with a function like date(){ echo 'something else'; } is the best solution.

Another approach would be to separate concerns: Let the script that does the actual work process dates it gets from elsewhere, for example by reading a string from the standard input. That's a bit like separating input routines from the actual processing. This strategy makes the processing more flexible because it can be plugged in to different processing chains. Even if it is unlikely that you'll ever want to use anything else than the system date this strategy does facilitate testing, a bit like the main advantage of injection over inheritance may be easier testability.

In this case, a trivial wrapper script would normally call /bin/date or equivalent and feed its output to the script, but for testing purposes one could echo something else.


Viewing all articles
Browse latest Browse all 223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>