I have a script that loops through a list of users to list files owned by these users
an so on...
when running this loop, I get this error "find: 0652-012 The user name does not exist." for each time the loop iterates. mind you that echo prints out the correct user name each time. its just the find command thats having problems.
And when I run find commands without looping, one user at a time i get results just fine. Is there something I'm missing?
I'm not sure what causes the error, because here could be several reasons, unprintable characters in your user-list file being probably the most common.
Still, there are some problems with your code anyway so it might be a good idea to correct these and test then:
1) old and deprecated syntax
backticks are only supported for backwards compatibility any more, so PLEASE don't use them: they are hard to read when mixed with quotation marks (single, double), they cannot be nested and they do have no advantage whatsoever for the modern way of doing the same: the "$(....)" construct. Actually this can do all the things backticks can not.
2) Your use of a "for"-loop
Bear in mind that a subshell invocation basically is expanded to text before the main command is parsed. That means: when the shell is evaluating a line first whatever is the result (output) of the command in the subshell is evaluated, then this replaces the subshell invocation, then the remaining command is evaluated.
It follows that all is fine as long as you don't hit the maximum length for input lines to the shell (usually 4096 or 8192 characters). If your list is really long the script will break with a "line too long" error.
As a general rule: if you work on lists of undetermined length do not use the "for"-loop but the "while"-loop with a pipeline. Instead of
write
3) Don't take variables for granted.
Yes, the shell allows this usage of variables that have not been declared before. No, you should still not rely on this mechanism. First, because it is a good idea to introduce variables explicitly with a "typeset"-statement, which gives you the opportunity to document what you write:
This will explain beyond any doubt what "$USER" is used for. This is maintenance-friendly once you have longer and more complex scripts.
Second, because it allows to declare some properties of the variable explicitly (i.e. type integer with the "-i" option of typeset or "-x", which makes this variable known throughout subshells). It is even possible to format your variable with some of the options to "typeset" ("-L"= convert to lowercase, "-U" to uppercase, etc.)
So, after all this, here is how i would have written your script:
Very new to the Korn Shell, but I've been looking up loops online and it seems this should work. I'm just trying to convert an ip range in variables $A and $B and iterate the individual ip's out to new lines. Unfortunately I get {152..155} instead of 152, 153, 154, and 155.
# for i in {$A..$B};... (8 Replies)
#!/bin/bashi
function userrecord() {
read -p "please enter a number: " a
clear
output=$(grep -w "$a" appraisalrecord)
b=$(echo $a | tr -dc )
if ]; then
echo -e "accepted\n"
else
echo -e "The input must be a numerical number\n"
userrecord
fi
if ]; then
echo -e "the ID has... (2 Replies)
for i in `seq 1 10 ` ; do
printf $i '\n';
done
gives me this:
1234567891064mbarch ~ $ (output followed by bash prompt) :(
I've tried so many ways to create a newline at the end. Does anyone have any ideas.. Thanks in advance. Sorry (7 Replies)
good afternoon forums.
i have a problem that ive been trying to work out all morning and cant seem to get my head around it.
what i have in my script is individual letters saved in different variables. so if the word unix was saved then 'u' would be stored in the variable 'wvar1' 'n' in 'wvar2'... (7 Replies)
I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends.
As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Hi guys,
I'm trying to loop through a number of files that is set by whatever is in a field.
eg.
The idea is to split FILELIST down into fields, it could contain 1 - 999 fields and it's bar delimited.
I thought simple, count the number of fields in the field and then loop... (1 Reply)
I have a problem validating my script. The start of my script begins like this:
then after this i have all of my script and functions.
at the end i close the loop with this code:
What i want to know is, how do i make the loop so that only Yes or no can be an answer?
and if... (7 Replies)
Hi there,
I have written a script to clear out log files from the var/tmp dir. It works up to a point. What I needed to do was to exit the script if there was no files to be deleted. I can get this working on a test script but when I implement it into my program it errors out with a `then` not... (3 Replies)
Here it wont terminate unless i take the not of my statement
#!/bin/bash
grabXML
parseXML
TAIL=5
#"$(cat dailyCasLog | tail -n 1)"
COUNT=200
LINE=5
#"$(cat dailyCasLog | head -n $COUNT | tail -n 1)"
echo $TAIL
echo $LINE
while ($LINE!=)
do
#$LINE">>currentLine
folderMaker
... (0 Replies)