I am inexperienced with scripting and it continues to baffles me speechless
I wrote a script so that it counts the number of subset of files (with different prefix) in all subdirectories under the current directory so that
find all subdirectories under the current directory and output the list to txt file
edit the output file so that .//directory becomes directory
from each subdirectory in the txt file, output the directory name to file list_of_data, then cd into that directory, then count all the number of subset of files under different prefixes and output the result to list_of_data.txt
The problem is, if I run the script by typing ./scriptname.sh I get the error message
but if I copy the content of the script and paste it in the terminal window it worked.
Thanks for your reply. As I said I am inexperienced I am sure there are much better way to write this.
Can you explain why the code works if I paste it in the terminal but it doesn't if I run it as a script?
As I explained above there are many subdirectories under the current directory. And inside each subdirectory there are a large number of files under different prefixes, like pict_1_1, pict_1_2, pict_2_1, pict_2_2, pict_2_3 etc etc etc
I want to count the number of file under each prefix from every subdirectory. with output like the sample output above into a txt file.
I would also appreciate it if you explain why you meant the extreme poor practice. I am keen to learn.
I think I am beginning to understand what the problem is. It seems the problem occurs with the sed command in the for loop. the error message
stems from the fact that there are 23 folder in current directory and maybe I don't truely understand the mechanism of the for loop.....as
then the
command tries to execute sed {1..23} all at the same time, hence the error.
During the for loop is it not like for i =1 then carries out the commands, then for i=2, carries out the command again etc etc until i=23? Why does sed trying to interpret i=1..23 all at the same time?
Still don't understand why the command runs when typed in terminal window but didn't when ran as script.
Is it possible to toggle back and forth between an xterm invoked from one tty, and a shell invoked from a different tty?
I am running Centos 7 with KDE and booting in non-graphic mode. After logging in on the default window (/dev/tty1) , I can then use ALT-F2 to access a new window (/dev/tty2),... (1 Reply)
hi,
i am trying to run this script.the name of script is final.sh
after i run it:
#./final.sh &
i grep the command
# ps -a | grep bash
and i see more then one processes runing 3!!
Please use code tags
how can i solve this problem?
my target script must always run in... (8 Replies)
I created a script called title
#!/bin/sh
echo "^0;$*^G"
It will change the terminal window titlebar to what ever I type after the script (title BIG would change titlebar to BIG instead of terminal) Is there a way to make it run so it will work on every terminal window that gets opened.... (1 Reply)
i have this script and when i ejecute it, the console tell me this " sintax error line 41 unexpected element "}" "
is the sintaxis ok?
#!/bin/bash
if ;then
{
exit 0;
}
if ; then
{
sudo /etc/init.d/apache2 start;
sudo /etc/init.d/mysql start;
php5 &
nautilus... (3 Replies)
I have a script that only works if I remove it from the looping scenario.
#!/bin/bash
# Set the field seperator to a newline
##IFS="
##"
# Loop through the file
##for line in `cat nlist.txt`;do
# put the line into a variable.
##dbuser=$line
echo "copying plugin..."
... (6 Replies)
Hi there,
the following script doesn't work. the first part works, then the second 'grep' fails with ': not found'. However, if I take out the second part (starting with the grep command) and put in a seperate script, it works.
everyone know what's wrong here? no two 'grep' in one script, that... (2 Replies)
Hello,,
Im verry new to scripting and have some problems with this script i made..
What it does:
It checks a directory for a new directory and then issues a couple of commands.
checks sfv - not doing right now
checks rar - it checks if theres a rar file and when there is it skips to... (1 Reply)
Hi there. I'm new to scripting in bash shell and I have this problem.
I'm trying to make a script that returns the greatest common divisor of two integer numbers according to Euclid's algorithm...
Here is, what I've done:
#!/bin/bash
m=$1
n=$2
while
do
if ; #line 8
then m=$m-$n... (1 Reply)
Howdie everyone...
I have a shell script RemoveFiles.sh
Inside this file, it only has two commands as below:
rm -f ../../reportToday/temp/*
rm -f ../../report/*
My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Hi,
I am a newbie here. Trying to find a way of writing a script to launch multiple terminal or console windows on solaris 9. I used to be able to do this using cmdtool on older versions of solaris and it was even possible to configure the size and screen position of the window and the title. ... (5 Replies)