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:
I am to create a script that checks a file for specific attributes. Read, write, execute, if the file is empty, and if the sticky bit is set. I have completed this step but I am stumped on how to add a simple counter and to have the script repeat the process of identifying access rights as many times as the person running the script wants. I am to prompt the user to enter another file name or an X to exit the script.
2. Relevant commands, code, scripts, algorithms:
3. The attempts at a solution (include all code and scripts):
any help would be greatly appreciated as I am completely stumped. If i remove the count syntax's, it prompts me to enter a filename but displays an error for line 5.
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course)
Westchester Community College, NY, United States, Cordino, COMSC118
As opposed to variable assignments where there should be no spaces around the assignment operator (hint). Also have a look at what the meaning of $1 is. It is often used to pass parameters (command line values) to a script, so the while loop does not seem to make much sense here and also the read statement needs to put its outcome somewhere in a variable, plus the count variable is not incremented inside a loop.
Last edited by Scrutinizer; 10-21-2014 at 11:26 PM..
It is not unusual to forget about good coding practices when writing scripts. This is wrong. You already have a script which checks for one file one time. Why don't you put what you have into a function (read about shell functions in the man page of your shell) and call that function?
If you have a command, say: "foocommand", and want to execute it a 100 times, this usually looks like (pseudocode)
Wouldn't it be easier to write something like this in shell code, instead of cramming all the functionality into one big loop? Incidentally it would also bring a solution to your other problem once you figure out how to pass parameters to a function.
Anopther thing:
This is neither wrong nor illegal, but you should avoid that anyway. Backticks are outdated and deprecated and generally not considered good style. Furthermore, in modern shells you do not need "expr" because any shell has a built-in way to handle integer operations. This:
Does the same in ksh and bash and is easier to read too. If you need process substitution (in this case you don't) you wouldn't use backticks either but:
is Bourne shell, works in any shell.
If there is a Posix/standard shell (or ksh or bash or zsh) the following is recommended because it avoids the external program expr
While
Quote:
(( count += 1 ))
only works in ksh93 and bash and zsh, and has no further speed enhancement.
This User Gave Thanks to MadeInGermany For This Post:
Hello,
I am having trouble calculating some numbers and I was hoping someone could help me solve this.
I have one file with 1 column and what I'm trying to do is add up the lines until a certain value is reach, then jump to where it last finished counting and continue.
so for ex: if I... (27 Replies)
I want to run my shell script to the limit number.Suppose I know in advance that MAX=5 then I want that my script run 5 times only.Something like below$ vi testingMAX=5COMMAND="ssh -l stpuser VHLDVWSAD001 /projects/st/utils/deploy/deployall.sh >/dev/null 2>&1 &" ; sleep 20;count=0while... (2 Replies)
Hello all!
This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician.
Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix:
... (16 Replies)
Hi,
I am writing a script which processes large number of files in a directory. I wanto display a counter which increment after processing each file. I am processing each file in a for loop. If I echo a variable with its value increasing with each file, I will get around 5000 lines as output.... (10 Replies)
I am executing the following script using 'awk -f process.awk out' where 'out' is the input file which consists of 5000 sequences. Each time it takes one sequence, run the below program by creating a directory, run the mfold command within that directory, running another shell script 'final5' and... (2 Replies)
I have looked high and low, tryed lots of diffrent things but cant get a simple counter to work right.
what i need is to increase a count ever time it finishes the test, pass or fail. example TEST PASS 1, NEXT TEST PASS 2,
I curently have
set foo o
while {$foo <=5} {
incr foo
puts... (1 Reply)
Hi,
I'm new to unix and have a problem? I'm writing a basic script in ksh and it is a basic quiz with 5 questions. I need to be able to accumulate the correct answers at the end and echo out the total correct answers, I cannot work it out? Please see script so far. If anyone can help that will... (2 Replies)
I have generated a script that will email a list of people if a certain PID is not running, using "mailx". I have the script running every 5 minutes as a cron job.
I want the script to stop sending an email, if the email has been sent 5 times (meaning PID is dead). I want this so that my... (3 Replies)
Hello:
Executing following script i'm getting error:
1=1+1: 0403-058 Assignment requires an lvalue.
It's not assuming the counter but i don't know why.
Some hint?
Thank you very much in advance.
#!/bin/ksh
<path>/tiempos.txt
num_exe=1
TIEMPOS=<path>/tiempos.txt
while ]
do (2 Replies)