Improvement in shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Improvement in shell script
# 8  
Old 06-19-2014
You could simplify the echo/read lines at the beginning:-
Code:
read var?"My prompt:- "

I agree with bakunin though, why is size important? Clear coding that is flexible if you need to adjust it later is far more important. As an exercise I once wrote a menu system in 60 lines no longer than 80 bytes just so I could print it on a single sheet.

It works just fine and was actually used for a production application, but I can hardly read it back now Smilie

Write out your logic, then work out the functions. Finally write your code to match your design and put useful comments in. Make it readable.

Also, make sure you do thorough error checking. Imagine if you issue a cd to a directory that does not exist, and then an rm * You might just destroy your home directory or wherever you were Smilie

Size should not be an issue. A neat way does not necessarily mean it will be smaller code, for example, using a loop to read a file and then use a single echo .... | cut .... command to extract the data from the line can be a single line, but using two or three variable substitutions may run far faster even if it does take more lines of code.

Sometimes, bigger is better Smilie


Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 9  
Old 06-23-2014
hi bakunin,

I really understand your thought but, here i am given a task of writing this code by reducing the no of lines. The person with least number of lines, will be recognised. Thats the reason i posted this. and i truely accept your piece of thought.
# 10  
Old 06-23-2014
Again -- why? Who has tasked you with this? They are being unreasonable.
# 11  
Old 06-24-2014
Quote:
Originally Posted by wasim999
hi bakunin,

I really understand your thought but, here i am given a task of writing this code by reducing the no of lines. The person with least number of lines, will be recognised. Thats the reason i posted this. and i truely accept your piece of thought.
So, why did you ask for our help. You know that you can easily convert your script into two lines of code by changing some newline characters to semicolon characters. It will be harder to read, harder to maintain, might not be editable with your editor (due to line length), and will be shunned as an example of extremely poor coding practices by anyone who writes code professionally.

But, if that is what you want, go ahead.

The professionals who volunteer their time here to help users learn how to write working code, avoid ridiculous metrics like this like the plague.

You started this thread saying you wanted to improve your code. Making it harder to read and harder to maintain is NOT an improvement!
# 12  
Old 06-24-2014
Sorry for what i posted. I wanted to learn unix in a good way. with good knowledge in it. Right now i am just 2 weeks old in unix trying find a good way of learning and ended up here. Sorry for this post. but i am eager to learn Unix.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance improvement in grep

Below script is used to search numeric data from around 400 files in a folder. I have 300 such folders. Need help in performance improvement in the script. Below Script searches 20 such folders ( 300 files in each folder) simultaneously. This increases cpu utilization upto 90% What changes... (3 Replies)
Discussion started by: vegasluxor
3 Replies

2. Shell Programming and Scripting

I need the improvement for my script

Hi All, Here is my script #! /bin/sh var1=some email id var2=some email id grep -i "FAILED FILE FORMAT VALIDATION" /opt >tmp2 diff tmp1 tmp2 | grep ">" >tmp3 if then cat tmp3 | mailx -s " Error Monitoring" $var2 else echo "Pattern NOt Found" | mailx -s " Error Monitoring" $var1... (1 Reply)
Discussion started by: Gopalak
1 Replies

3. UNIX for Advanced & Expert Users

linux os improvement

can anyone help to share the knowledge on linux os improvement? 1) os account - use window AD authentication, such as ldap, but how to set /etc/passwd, where to put user home? 2) user account activity - how to log os user activity share the idea and what tools can do that...thx (5 Replies)
Discussion started by: goodbid
5 Replies

4. Shell Programming and Scripting

Looking for improvement to script that compresses a directory that is 2 months old

I write reports daily to a directory that is named with the month and year. I wanted to compress all but the last two months worth of these directories to save space. I am going to cron a job to run on the first of each month to do this clean up. I didn't have zip/unzip on my AIX environment so... (0 Replies)
Discussion started by: slatoms
0 Replies

5. Shell Programming and Scripting

Any improvement possible in this script

Hi! Thank you for the help yesterday This is the finished product There is one more thing I would like to do to it but I’m not to certain On how to proceed I would like to log all output to a log in order to Be able to roll back This script is meant to be used in repairing a... (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

6. Shell Programming and Scripting

Script ready but might need some improvement.

Hi All, I have written a script which does some editing in the files, based on user input.This might not be the most elegant way of doing it and there would be many improvements needed. Please go through it and let me know how it could be improved. Suggestions are welcome!! Thanks!... (2 Replies)
Discussion started by: nua7
2 Replies

7. Programming

File - reading - Performance improvement

Hi All I am reading a huge file of size 2GB atleast. I am reading each line and cutting certain columns and writing it to another file. Here is the logic. int main() { string u_line; string Char_List; string u_file; int line_pos; string temp_form_u_file; ... (10 Replies)
Discussion started by: dhanamurthy
10 Replies
Login or Register to Ask a Question