I sincerely apologize for not being able to test the code I suggested you try on the system I'm using (and, therefore, missing a closing single-quote in the code I provided).
I'm sorry that you believe that I should be required to download all of the software you're using on your system onto my system in order to try to help you understand the code you're using. I AM NOT GOING TO DO THAT! I am perfectly happy with the way awk works on my system even though awk on your system has some (non-standard) extensions that do some nice things in some cases. What those extensions do has nothing to do with what you're doing nor with what you're trying to do. The difference we are seeing is because you are doing something that the standards describe as producing "unspecified behavior" and your version of awk produces a different unspecified behavior than my version of awk produces.
All that I was trying to do with the awk statement I was trying to get you to run was to show that the value of $input and the value of $(ls) inside your awk script have absolutely no relationship to the value of $input or the value of $(ls) in bash outside of your awk script.
Nothing in your explanation in English of what the expression in your awkif statement is true. The awk variable input is not defined anywhere in your awk code (only the shell variable input is defined; not the awk variable input). In bash$(ls) is a command substitution that runs the ls command and substitutes the output it produces. In awk$(ls) is a command that expands to the contents of the field number specified by the value of the awkls variable converted to an integer. The awk and shell == operators are a request to compare the two operands on both sides of that operator. If there is more than one file in a directory and one of those files is the name of the file you're processing, there is absolutely no way that the name of that one file can possibly be equal to the list of names of files that are present in that directory. Since you are seeing the output you're seeing, your version of awk has to be expanding both sides of the comparison to the expansion of $0 which (in awk) is the entire contents of the current input line.
With the missing quote added AND assuming that you had already defined the shell variable input as you had shown before AND assuming that the file named AfileinDir contained the two input lines:
I would expect the sequence of commands:
to produce output very similar to the following:
Despite what you said, absolutely nothing in the code above assigns any value to the awk variables input and ls; that code only displays the values that the expression in your awkif statement expression are comparing (i.e., the entire contents of the current line in AfileinDir on both sides of the ==).
Maybe if we rewrite that as:
which (if you set the contents of the file named AfileinDir to the contents I specified above), I expect will produce the output:
you will see that $input and $(ls) in your awk script do not expand to the strings you think they will expand to.
I know that you don't want to just use the shell (i.e. bash) to determine whether or not the variable read from your script's user (i.e. input) is the name of a file in your current directory, but that is exactly what the simple bash command:
that I suggested in post #4 did for you. If the shell variable input contains the name of a regular file that exists in the current directory, it will perform the while loop in the then clause of the if statement. Otherwise, it will print the name of the file the user supplied and say that that file is not in this Directory and then exit with a non-zero exit status as specified in the else clause of the if statement.
This User Gave Thanks to Don Cragun For This Post:
I know that this is a relative question but can someone give me an idea of what would be considered a high number of context switches?
I am running vmstat and show a cs value of between 5000 and 6000 on a 4 processor system. How can I deduce if this number is high or not?
Also, the timeslice... (2 Replies)
there are several same servers(process) on more than one server(machine) providing the same service.
we store session/context within the server(process), if the same client login, he will be directed to the very server service for him last time.
But, if a server(machine or process) down, the... (1 Reply)
Hi,
There's a file with below contents which I have to read based on the input parameter provided by the user.
FILE_ID=1
FILE_FTP_ID=ftp.server1.com
FILE_FTP_USER=user1
FILE_FTP_PASS=pass1
FILE_ID=2
FILE_FTP_ID=ftp.server2.com
FILE_FTP_USER=user2
FILE_FTP_PASS=pass2
FILE_ID=3... (6 Replies)
Hello,
I have a file that I want to be able to split at specific positions. For example in the file below I want to be able to split at every occurence of 2 at the start of a line, into multiple files.
2 abc PQRST
abcRSTG
2 cde FGKL
abcLKGRG
ABCLKgrg
2 lmn OPT
lmopqrst
uvwxyz
... (1 Reply)
Hi all,
I've got this question that i need to solve:
"Type `vmstat -s; vmstat -n 1 5; vmstat -n 1 5; vmstat
-s` to your Ruby interpreter. Then terminate your Ruby session. Run the Unix com-
mand vmstat -s; vmstat -n 1 5; vmstat -s in the same terminal window you had
been using for Ruby. Did... (1 Reply)
Ive got multiple PCs, sharing an NFS mounted home dir. For certain apps I would like to keep the config files host specific. Easy solution is to create symlinks to local folders for configs. Ideally I would still want the .config files to reside in the user home folder.
Is it possible to... (2 Replies)
In a kernel based on 2.6.27:
In the schedule() routine they have a local variable switch_count:
/*
* schedule() is the main scheduler function.
*/
asmlinkage void __sched schedule(void)
{
struct task_struct *prev, *next;
unsigned long *switch_count;
struct rq... (2 Replies)
If suppose a middle level interrupt is being serviced and a high priority interrupts comes in then in that case what all process will take place.
The interrupt context switch will happen. But where will the interrupt context be saved?
Is there something called as part process data area? (4 Replies)
Hi
Just wondering ... do you have an example of context that would demonstrates how usefull the awk notation can efficiently be used ?
Thx :rolleyes: (6 Replies)