The first line is
Is it the problem? I tried changing that to csh and then even directly the script doesn't work. I don't know why I used bash at that time though :/
The echo testing works. Thanks again man, appreciate it.
---------- Post updated at 05:44 AM ---------- Previous update was at 05:28 AM ----------
When I tried to change the script to csh it says something like this -
I checked all the input files and they're correct. :/
---------- Post updated at 06:12 AM ---------- Previous update was at 05:44 AM ----------
Assignments like count_C=$(grep -c C mols) do not work in csh (csh would need the set keyword before).
So the shebang #!/bin/bash is correct (of course it must exist).
Your script expects to be started in a certain directory.
So put a cd command before you invoke your script,
or change your script to do the necessary cd first!
This User Gave Thanks to MadeInGermany For This Post:
The scripts name is GEN_POSCAR, so if I say like this-
won't it say it's not a directory? Or am I understanding something wrong here? :/
---------- Post updated at 07:38 AM ---------- Previous update was at 07:01 AM ----------
And I should add if I put the .cell file in the same directory with the forloop script it does the work as usual which probably means it's not going to the directories cause it shows the following error message :
But these directories exist there :/
The scripts name is GEN_POSCAR, so if I say like this-
won't it say it's not a directory? Or am I understanding something wrong here? :/
If the scripts (short) name is "GEN_POSCAR", then it is a file in directory "/scratch/scratchdirs/saleheen/Scripts/My-scripts". The full name would be "/scratch/scratchdirs/saleheen/Scripts/My-scripts/GEN_POSCAR",
but you were told by MadeInGermany to do this:
As i sense there is some confusion about the directory concept, here it is:
Every file is placed somewhere under the "root"-hierarchy, which is denominated by "/". "/" is the topmost directory on every UNIX- (and UNIX-like) system. Now, every directory can hold two (in fact there are more, i am simplifying here) types of entries: other directories and files. Each of these other directories can also hold directories and files, and so forth. Every directory si separated by the directory "above" by a slash "/".
Therefore, "/scratch/scratchdirs/saleheen/Scripts/My-scripts" means: in the root directory "/", there is a directory "scratch". Inside "/scratch" there is another directory "scratchdirs", hence: "/scratch/scratchdirs". Inside "/scratch/scratchdirs" there is the directory "salaheen" and inside this is "Scripts", asf.. Inside the bottom directory "/scratch/scratchdirs/saleheen/Scripts/My-scripts" is a file called "GEN_POSCAR", which holds your scripts source code.
Think of it like that: you open the topmost box. Inside you find several smaller boxes (subdirectories) and some loose sheets of paper (files). Opening one of the smaller boxes you find again smaller boxes (sub-subdirectories) and other loose sheets of paper. And so on, until a box contains only loose sheets and no other boxes.
Thanks a lot for clearing that up for me, bakunin. I was just wondering, if I do cd scratch... and then ./GEN _POSCAR thing doesn't that mean I am running the script in the script's directory? Shouldn't I try to run the script in my current directory tree?
I did what you said but still it shows the same error message. I am curious, the first line of the error message
why does it say that? I have the .cell file in my directory tree! Thanks a lot man! Really appreciate what you are doing.
Last edited by rbatte1; 07-29-2014 at 01:20 PM..
Reason: Added ICODE tags for inline code.
I did what you said but still it shows the same error message. I am curious, the first line of the error message
why does it say that? I have the .cell file in my directory tree!
The error message is coming from inside the script and it is, because where the script is there is no such file as "*.cell". Note that "*.cell" is meaning all the files in the current directory with a name ending in ".cell". But what "current directory" means depends on where you were when you started the script.
This is why you should always use absolute paths (paths starting from the root dir) in scripts. For instance:
Notice, that the full path is only named once, then used throughout the script. Think about what content each of the variables holds at which time and what the complete commands with expanded variables would look like. I suggest you adapt the script a bit and play around with it.
Having said this, you cycle through all directories and call the script for each directory once, but the directories you cycle through are nowhere mentioned in your script. You probably should do something with the directory names you cycle through, otherwise there is no sense in doing this, no?
What you do is:
What you probably want to do is something like:
Supposing that the script can do something with the directory name it gets passed. To understand how to do something with passed parameters you should read the man page of your shell (mind you, "bash" or "ksh", but DEFINITELY NOT csh! Do not even consider to use csh for scripts, the damned thing is buggy to no end!).
Here is a short introduction:
save this to a file "myparam.sh", slap on the executable-bit and issue:
Thank you so much bakunin. If I'm understanding correctly, you're telling me to use the absolute path in my script. I actually didn't get this part of your answer, I'm so sorry, I'm just a newbie.
Quote:
Having said this, you cycle through all directories and call the script for each directory once, but the directories you cycle through are nowhere mentioned in your script. You probably should do something with the directory names you cycle through, otherwise there is no sense in doing this, no?
When I say
shouldn't it go to the child directories where my input files are? Normally what I do is I go to each child directory one by one and call my script like this:
The same way I wrote in the script. When I'm setting my subdirectpry tree as the variable and calling that variable through the loop one by one, why do I have to mention directory name? And this part-
Quote:
What you do is:
Code:
./dir1: script ./dir2: script ./dir2/dir1: script ./dir2/dir2: script ...
What you probably want to do is something like:
What does that mean? What my understanding is ./dir1 , going into directory1 and then run the script. why there's ./dir1 at the end too? I'm so sorry man, may be I should read something before just posting my problems. Since I'm stuck with csh (Trying to go to bash) would you be kind enough to provide some easier books on csh for beginners like me?
Just started shell scripting for the first time today :D Can anyone tell me why I get the error "foreach: Words not parenthesized." for my following code? The program takes in a list of arguments.
foreach card ($argv)
echo Hello
end (3 Replies)
Hi everyone I'm new to unix and encountered a small problem i couldnt find out a reason why it doesn't work..please help..
in my csh script when i tried to use the foreach loop like this:
foreach x ( ls )
echo $x
end
when i tried to run it, it printed out 'ls' to the std out instead of... (3 Replies)
Dear all,
I wrote a script to download files and move files in directories according to their name.
Now here is the problem:
Both p101 and p360 data download successfully, but when I move them according to the year and month, only p101 data can be placed at the right location, p360,... (1 Reply)
I am trying to make a script for my Counter-Strike: Source servers. What i am wanting it to do is for it to restart each server, the only way i can think of doing this in through for each.
Years what i have at the moment.
server_start() {
START=`ps x | grep SCREEN | grep $SRV | cut -d '?' -f... (5 Replies)
Hello all,
I'm working on a foreach loop to compare a couple sets of data. However, each datafile includes a header row. I'm wondering if it is possible to tell the foreach loop to skip the first line of data.
I've been using the basic code as follows:
foreach line ("`file.csv`")
set... (2 Replies)
Hey all,,
I know cshell is harmful:) but I am using this just "to know" - for educational purposes!... not for a long-term use.
lets say i have a list..
set arr=(x y z e f)
I wanna iterate the list with foreach ,, not with while.!!
foreach i $arr
echo $i
end
does not work (2 Replies)
I have a foreach loop in a csh script and I noticed that it tries to find the files with the pattern *$searchpt* in the file name. I'm confused as I never specified checking for the files.
foreach f ( *$searchpt* )
set fnew = `echo $f | awk -v searchpat=$searchpt \
... (1 Reply)
Hi everyone
Does anyone know what is wrong with this script. i keep getting errors
foreach filename (`cat testing1`)
set string=$filename
set depth=`echo "$string"
echo $depth
end
the error is the following
testing: line 1: syntax error near unexpected token `('
testing: line 1:... (3 Replies)
Hi Guys,
I have a loop which uses a wildcard
i.e. foreach f (*)
but when I execute the tcsh file in unix then it gives me an error
->>>>>>>foreach: words not parenthesized<<<<<<<<<<-
Any help. (1 Reply)