I have a shell script app1.sh and a tree of folders, but I don't know how to execute this shell inside each folder. Here is   This script recieves an string, an integer and a file as arguments to work. The idea is to execute it in 4 folders inside a directory.  Thanks all for your help :)
121871
I'm attempting to write a script that will be run in a given directory with many single level sub directories. The script will cd into each of the sub directories, execute a command on the files in the directory, and cd out to continue onto the next directory. What is the best way to do this?
46113
I am new to shell scripts and many books have written that use #!(sha-bang) line in starting of the script to invoke the interpreter .And this will invoke a new shell for script and do the interpretation line by line.But one of my basic script is still running without the magic line.  so my questions are:   from where did my basic script get the interpreter. how did the script manages to locate the interpreter.   now let me tell you about my basic script it just contains the following line:  echo "basic script without the magic lines"
27654
I have a script which finds files in the directory specified by user.    #!/bin/bash  # make sure about the correct input if [ -z $1 ] then     echo "Usage: ./script_name.sh    path/to/directory" else     DIR=$1     if [ $DIR = '.' ]     then          echo "Find files in the directory $PWD"     else           echo "Find files in the directory $DIR"     fi      find $DIR -type f -exec basename {} \;  fi   if I input    $ ./script_name.sh .   script gives me correct substitution ./ to $PWD and shows (for example)    $ Find files in the directory /root/scripts     But I can't make a decision how to substitute ../ to the name of the directory  immediately above in the hierarchy.  If I input    $ ./script_name.sh ..     script gives me the output    $ Find files in the directory ..     Does anybody know how to substitute ../ to the actual name of the directory?
27159
I am new in Linux so here is my very basic question. I have a directory with 41 folders. I need to create a loop so that the process goes into each folder, copy all the files and then paste everything in a specific folder.   Any idea how to approach this? It would be a lot of clicking without a code solution  In the image you can see all the folders I need to access and the output folder where I want to paste everything (zPASTE_EVERYTHING_HERE)    My path is: /shared/home/data/output  Would like to paste everything in: /shared/home/data/output/zPASTE_EVERYTHING_HERE
18003
I was wondering if the following two ways of running a bash script are equivalent?  . ./myScript.sh  source myScript.sh  Are they both running the content of the script instead of running the script, i.e. not creating a subshell for running the script?
66311
Possible Duplicate:          I was trying to figure out how to export my environmental via script instead of changing my .bashrc file.   I found  that said:     Variables can only be exported to subordinate processes, you can't   pass them back up to the parent. If you really want your script to   affect the parent shell's environment, run the script as  . ./yourprogram    I just want to know what the difference is between . ./script and ./script?  When I look at it, they booth mean to me, run the script from the current directory?
26653
I know that shell scripts just run commands as if they were executed in at the command prompt.  I'd like to be able to run shell scripts as if they were functions... That is, taking an input value or string into the script.  How do I approach doing this?
57173
to open send to folder in windows 7, we type  shell:sendto  and to open apps folder in windows 8, we type  shell:appsfolder  first of all, i would like to know what is this syntax known as (shell: something)  secondly, if anybody can tell me, please give the complete list of commands similar to this  thanks Gagan
18999
I have a small script that loops through all files of a folder and executes a (usually long lasting) command. Basically it's  for file in ./folder/*; do     ./bin/myProgram $file &gt; ./done/$file done   (Please Ignore syntax errors, it's just pseudo code).  I now wanted to run this script twice at the same time. Obviously, the execution is unnecessary if ./done/$file exists. So I changed the script to  for file in ./folder/*; do     [ -f ./done/$file ] || ./bin/myProgram $file &gt;./done/$file done   So basically the question is: Is it possible that both scripts (or in general more than one script) actually are at the same point and check for the existance of the done file which fails and the command runs twice?   it would be just perfect, but I highly doubt it. This would be too easy :D If it can happen that they process the same file, is it possible to somehow "synchronize" the scripts?
66160
I can run this command from my command line prompt:  cp -r folder/!(exclude-me) ./   To recursively copy all contents of folder except for the subdirectory named exclude-me into the current directory.  This works exactly as intended.  However, I need this to work in a bash script I've written, where I have this:  if [ -d "folder" ]; then   cp -r folder/!(exclude-me) ./   rm -rf folder fi   But when I run the script:  bash my-script.sh   I get this:  my-script.sh: line 30: syntax error near unexpected token `(' my-script.sh: line 30: `  cp -r folder/!(exclude-me) ./'   And I'm at a loss as to why it works from the command prompt, but the exact same line doesn't work in a bash script.
922
This may be a silly question, but I ask it still. If I have declared a shebang  #!/bin/bash    in the beginning of my_shell_script.sh, so do I always have to invoke this script using bash  [my@comp]$bash my_shell_script.sh   or can I use e.g.  [my@comp]$sh my_shell_script.sh   and my script determines the running shell using the shebang? Is it the same happening with ksh shell? I'm using AIX.
58568
I am trying to make a script like this:  #!/bin/bash sudo -s something...   When I execute it, I get a new shell but something is executed only when I exit the shell created by sudo -s, not inside it.  Any help?
81080
I'm creating a simple bash script and I want to create a select menu in it, like this:  $./script  echo "Choose your option:"  1) Option 1   2) Option 2   3) Option 3   4) Quit     And according to user's choice, I want different actions to be executed. I'm a bash shell scripting noob, I've searched the web for some answers, but got nothing really concrete.
17208
I want to have a shell script like this:  my-app &amp; echo $my-app-pid   But I do not know how the get the pid of the just executed command.  I know I can just use the jobs -p my-app command to grep the pid. But if I want to execute the shell multiple times, this method will not work. Because the jobspec is ambiguous.
7695
I need to copy /root/nbu/file1.sh to every user's home directory if user's id is even number.  Trying to execute following script:  #!/bin/bash cat /etc/passwd | while read LINE do     username=$(awk -v var="$LINE" -F: '{         if ($3 % 2 == 0)            print $1         }')     cp /root/nbu/file1.sh ~"$username" done   And it does nothing. If I echo cp /root/nbu/file1.sh ~"$username" command and execute it directly in the script, it works.  I guess the problem is that ~ gets expanded in the bash script, but can't figure out how to solve this problem.  Thank you in advance.
17409
From a shell script, how do I check if a directory contains files?  Something similar to this  if [ -e /some/dir/* ]; then echo "huzzah"; fi;   but which works if the directory contains one or several files (the above one only works with exactly 0 or 1 files).
66951
I have this script:  echo $HOME cd $HOME cd / cd /usr/local/src/   When I run it like this  . script.sh   I get this output:  /home/user : No such file or directory : No such file or directory : No such file or directory   If I run it normally (I added #!/bin/bash before the first line)  sh script.sh   I get this output:  : not found.sh: 2: script.sh /home/user script.sh: 3: Can't cd to /home/user script.sh: 4: Can't cd to / script.sh: 5: Can't cd to /usr/local/src/   The script was run from $HOME directory each time. If I run each command one by one from shell, it executed without problems (invoking cd $HOME from within $HOME simply didn't change directory).  What must I do to make this work?