Skip to main content
17 events
when toggle format what by license comment
May 21, 2021 at 3:01 vote accept Wenhan Xiao
May 20, 2021 at 14:05 history edited Kusalananda CC BY-SA 4.0
Markup, reformulations
May 20, 2021 at 12:47 answer added Kusalananda timeline score: 1
May 18, 2021 at 11:18 comment added pLumo I already told you ... with read filename you exactly read one filename! You can not iterate them easily. And if you do, it will choke on whitespace.
May 18, 2021 at 9:26 comment added Bodo @WenhanXiao YOur script still contains errors as already written in comments. Consider using shellcheck.net to check your script. In case you re-typed your script, please copy&paste exactly the script you run on your system and copy&paste the exact input/output/error messages. Instead of using the read command to get the file name(s) I suggest to use command line arguments. You could run your script as linecounter.sh cat dog cow and implement it like for filename in "$@"; do ... ; done
May 18, 2021 at 9:23 comment added Wenhan Xiao @pLumo i have edited everything, hope u understand from what i edited
May 18, 2021 at 9:14 comment added Wenhan Xiao @Kusalananda , yes when i run the script, i use , linecounter.sh to run This script is use to run a single file at a time, but i want it to be in such a way that even if i run many files at the same time, it will display as per normal
May 18, 2021 at 9:10 history edited Wenhan Xiao CC BY-SA 4.0
added 286 characters in body
May 18, 2021 at 9:09 comment added Kusalananda In short, you are showing a script that can't run (not for a single file, not for multiple files at once). Then you tell us that this script works for a single file. We don't know what to believe.
May 18, 2021 at 9:07 comment added Kusalananda If you run ps -p$$ on the command line and it says tcsh, then your interactive shell is tcsh. The tcsh would run your script with /bin/sh if your script does not have a proper #!-line. This means that your script is a sh script, not a tcsh script. As a sh script, it has several issues, like having spaces around = in an assignment, just like the script(s) in your previous question and answer. This script also lacks a fi at the end, and you can't test for the existence of multiple files at once with -e. Variables need to be quoted to prevent word splitting and globbing.
May 18, 2021 at 9:02 comment added Wenhan Xiao hi @Kusalananda i believe its tcsh as after i run [ps -p$$], its shows, CMD as tcsh
May 18, 2021 at 9:01 history edited Wenhan Xiao CC BY-SA 4.0
deleted 23 characters in body
May 18, 2021 at 8:59 comment added Kusalananda Your script does not display file not found when run with the tcsh shell. It says -e Enter file name: \c followed by the error read: Command not found.. If you run it with bash, it terminates with script: line 10: syntax error: unexpected end of file. What shell are you actually using?
May 18, 2021 at 8:50 comment added Arkadiusz Drabczyk I tried to run your script with tcsh as you tagged but I get -e Enter file name: read: Command not found. filename: Undefined variable.
May 18, 2021 at 8:47 comment added pLumo Of course it does not work. Your command is [ -e "cat dog cow" ], but a file with name "cat dog cow" does not exist.
May 18, 2021 at 8:45 comment added pLumo Please fix your shell script. (1) Quote your variables, (2) Remove space at total =.... (3) You're missing a fi.
May 18, 2021 at 8:39 history asked Wenhan Xiao CC BY-SA 4.0