I have a bash shell that even though it does not look pretty is working very well. Some of the steps are repetitive, something like this:
Which in reality is 4 steps repeated 4 times:
I am trying to simplify it but I am not quite sure how to go about it.
Any help will be very much appreciated
Standard refactoring steps:
1. Format you code - http://www.linux-kheops.com/doc/perl...ert/fmt.script and gawk --profile can help. (here you need only in gawk pretty-printing facilities)
2. Rename variables.
3. Extract functions,
4. Comment.
5. Do everything in small steps, test continuously and save you changes in git (it's really easy and very, very useful).
In addition to bartus11:
You can split this function father (to aliases, functions, command variables) to define easy understandable and testable small steps.
===
Well, after refactoring you should change this function to something like this (names should be renamed, of course):
Some question about the usage of shell scripts:
1.) Are the commands of the base shell scripts a subset of bash commands?
2.) Assume I got a long, long script WITHOUT the first line.
How can I find out if the script was originally designed für "sh" or "bash"?
3.) How can I check a given... (3 Replies)
Hi All,
I need some urgent help regarding some info.
I have a cluster of servers for which I have two scripts for management.
control.sh is a bash script meant for restarting/stopping the servers.
manger.ksh is a kshell script. It is a master script to manage restarting/stoppping and... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Test that exactly one command line argrument is enter from the command line. If not, display the usage... (1 Reply)
Experts,
I am newbie in shell scripting. I want to write Bash shell scripts corresponding to windows bat files. I have installed cygwin at c:\cygwin and i am trying to crate the sh file using vi editor. i am not able to understand how to use linux/unix convention for the code. following is my... (15 Replies)
Experts,
I am newbie in shell scripting. I want to write Bash shell scripts corresponding to windows bat files. I have installed cygwin at c:\cygwin and i am trying to crate the sh file using vi editor. i am not able to understand how to use linux/unix convention for the code. following is my... (1 Reply)
Again a comment removal requirement from me, refer my previous problem & solution for removing comment from ruby scripts: https://www.unix.com/shell-programming-scripting/118296-best-way-removing-comment-ruby-program.html
This time, it is for stripping of comments from Shell Script. I search for... (2 Replies)
Hi,
I have to write a program to compute the checksums of files
./script.sh
I wrote the program using bash and it took me forever since I am a beginner but it works very well.
I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Hi all,
plz can anybody tell me that if a script written for Bash shell also work for other shells and if yes , how ???
Thanks and Regards
SONAL (2 Replies)