Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi i need to create a bashcript that remembers how many times it has been executed
For example
sh myscipt
This is the 1 time
sh myscript
This is the 2 time
and so on... how i can implement this? I have thought to store the counter into a file or into a shell variable?? What do u want to suggest me and how i can implement this?
Thx a lot
Why not have the script open itself and write the number of times to the bottom of itself? Or make it find the line starting something like "RUN: " and append the number of times it's been executed there?
Or make a file ".myscript" (a hidden file) in the home directory that contains the number of runs. You could use the env variable idea, but then that will be reset at each boot.
I personally like the idea of the script editing itself. It sounds messy and like bad coding style, which I am all for in casual computing. Hooray for the IOCCC.
If you wanted to use an evironment variable, you could write it to a line of .bashrc or some other startup script so that the variable is restored each time the computer reboots. However, this might be even more hairy than the previous suggestions.
Last edited by Pestossimo; 07-20-2005 at 05:46 PM.
Thx a lot guys but your answers didnt help so much...... I want each time to remember the number of executes times... because i want to create each time a directory and put in there some files ....
sh myscript
creating folder 1
copying fles in the folder
sh myscript
creating folder 2
copying files in the folder
When i reboot the computer
sh myscript
creating folder 3
copying files in the folder
hi there,
the "remember" feature does not exist.
what you can do is:
if you have a standard name for you directories - i.e. all of them are called fooXX, you can just increment your variable based in how many directories foo* exists.
regards
slackie1000
I was searching inside the /etc/rc.d/ scripts to find out something. I thought the different run level scripts can give some ideas for achiecing this. But I gave up after spending some hours.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.