I find a list of bam files using $bams=$(find /data/and/ -type f -regex &quot;.*\.bam&quot;) #/data/DNA128441.bam #/data/DNA128442.bam #/data/DNA128443.bam  And wanted to feed in a script test.sh #!/bin/bash bam=&quot;$@&quot; echo &quot;You provided the arguments:&quot; ${bam} s=${bam##*/} r1=${s%.bam}_R1.fastq r2=${s%.bam}_R2.fastq echo $r1 echo $r2  But when I run: $bams=$(find /data/and/ -type f -regex &quot;.*\.bam&quot;) ./test.sh $bam You provided the arguments: /data/and/DNA128441.bam /data/and/DNA128342.bam /data/and/DNA128343.bam DNA128343_R1.fastq DNA128343_R2.fastq  My question is how to make it process one by one such like a desired output: $bams=$(find /data/and/ -type f -regex &quot;.*\.bam&quot;) ./test.sh $bam You provided the arguments: /data/and/DNA128341.bam DNA128341_R1.fastq DNA128341_R2.fastq You provided the arguments: /data/and/DNA128342.bam DNA128342_R1.fastq DNA128342_R2.fastq You provided the arguments: /data/and/DNA128343.bam DNA128343_R1.fastq DNA128343_R2.fastq
651
I have a complex command that I'd like to make a shell/bash script of.  I can write it in terms of $1 easily:  foo $1 args -o $1.ext   I want to be able to pass multiple input names to the script. What's the right way to do it?    And, of course, I want to handle filenames with spaces in them.
58265
I have a bash script looping through the results of a find and performing an ffmpeg encoding of some FLV files. Whilst the script is running the ffmpeg output seems to be interupted and is outputting some strange looking errors like the one below. I've no idea what is going on here. Can anyone point me in the right direction?  It's as though the loop is still running when it shouldn't be and interupting the ffmpeg process.  The specific error is:  frame=   68 fps= 67 q=28.0 00000000000000000000000000001000size=      22kB time=00:00:00.50 bitrate= 363.2kbits/s dup=1 drop=0     Enter command: &lt;target&gt; &lt;time&gt; &lt;command&gt;[ &lt;argument&gt;] Parse error, at least 3 arguments were expected, only 1 given in string 'om/pt_br/nx/R3T4N2_HD3D_demoCheckedOut.flv'   Some more details from the ffmpeg output:  [buffer @ 0xa30e1e0] w:800 h:600 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:flags=2 [libx264 @ 0xa333240] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64 [libx264 @ 0xa333240] profile High, level 3.1 [libx264 @ 0xa333240] 264 - core 122 r2184 5c85e0a - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=cbr mbtree=1 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=500 vbv_bufsize=1000 nal_hrd=none ip_ratio=1.40 aq=1:1.00 Output #0, mp4, to './mp4s/pt_br/teamcenter/tc8_interactive/videos/8_SRM_EN.mp4':   Metadata:     audiodelay      : 0     canSeekToEnd    : true     encoder         : Lavf54.3.100     Stream #0:0: Video: h264 (![0][0][0] / 0x0021), yuv420p, 800x600, q=-1--1, 500 kb/s, 30k tbn, 29.97 tbc     Stream #0:1: Audio: aac (@[0][0][0] / 0x0040), 44100 Hz, mono, s16, 128 kb/s Stream mapping:   Stream #0:1 -&gt; #0:0 (vp6f -&gt; libx264)   Stream #0:0 -&gt; #0:1 (mp3 -&gt; libfaac) Press [q] to stop, [?] for help error parsing debug value0 00000000000000000000000000000000size=      13kB time=00:00:00.-3 bitrate=-3165.5kbits/s dup=1 drop=0     debug=0 frame=   68 fps= 67 q=28.0 00000000000000000000000000001000size=      22kB time=00:00:00.50 bitrate= 363.2kbits/s dup=1 drop=0     Enter command: &lt;target&gt; &lt;time&gt; &lt;command&gt;[ &lt;argument&gt;] Parse error, at least 3 arguments were expected, only 1 given in string 'om/pt_br/nx/R3T4N2_HD3D_demoCheckedOut.flv'   The script is as follows  #!/bin/bash LOGFILE=encodemp4ize.log echo '' &gt; $LOGFILE STARTTIME=date echo "Started at `$STARTTIME`" &gt;&gt; $LOGFILE rsync -avz flvs/ mp4s/ --exclude '*.flv' #find flvs/ -name "*.flv" &gt; flv-files # The loop find flvs/ -name "*.flv" | while read f do FILENAME=`echo $f | sed 's#flvs/##'` MP4FILENAME=`echo $FILENAME | sed 's#.flv#.mp4#'` ffmpeg -i "$f" -vcodec libx264 -vprofile high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -threads 0 -acodec libfaac -ab 128k "./mp4s/$MP4FILENAME" echo "$f MP4 done" &gt;&gt; $LOGFILE done
79113
I'm trying to make a bash script that would make a series of directories  and requesting a parameter of how many directories should be created.  $&gt; ./createDir.sh 5  $&gt; ls  ex_01 ex_02 ex_03 ex_04 ex_05   I tried using mkdir ex_{01..$1} but it does not seem correct. How could I make this work (without using any loop)?
45767
I am seeing different results from the find command between being run manually on the command line vs run in a script.   If I run the following on the command line:   find . -name '*.txt' ! -name '*20120427.txt'    I get all the .txt files in a directory except for the ones with the date that I want to avoid.  But when I have this same line in a script with a variable to identify the date:  FDATE=`date +%Y%m%d` find . -name '*.txt' ! -name '*${FDATE}.txt'    The script finds all the .txt files including the ones with the date I want to avoid.   The only difference between the 2 is that I am passing the FDATE variable in the script. Is there something obvious I am missing? I do not understand why the results are coming out different.
59964
I can't for the life of me figure out how find with the test -name works.  I run find / -name *in and returns a bunch of results:  /sbin /sbin/sulogin /dev/stdin   to name a few.  It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it. Also because I don't have any files in the current directory that match *in. Plus, single quoting *in yields the same results, which further supports that this can't be filename expansion.  The documentation leads me to believe that find with -name uses regular expressions, but the regex pattern *in doesn't match the results I showed above.  Can someone enlighten me?
111306
I want to remove certain files using find and -exec. But unlikely bash tells me, that I'm "missing" some argument.   find . -name *.png -exec rm {} /;   what do I miss?  same "missing argument" return for my attempt to rename some files:  find . -name ic_launcher.png -exec mv {} other_name.png /;   Can somebody tell me, what bash does miss, and why this command isn't successful?
15319
While answering  it struck me that it seems find, in the following example, potentially would process files multiple times:  find dir -type f -name '*.txt' \     -exec sh -c 'mv "$1" "${1%.txt}_hello.txt"' sh {} ';'   or the more efficient  find dir -type f -name '*.txt' \     -exec sh -c 'for n; do mv "$n" "${n%.txt}_hello.txt"; done' sh {} +   The command finds .txt files and changes their filename suffix from .txt to _hello.txt.  While doing so, the directories will start accumulating new files whose names matches the *.txt pattern, namely these _hello.txt files.  Question: Why are they not actually processed by find? Because in my experience they aren't, and we don't want them to be either as it would introduce a sort of infinite loop. This is also the case with mv replaced by cp, by the way.  The  (my emphasis)     If a file is removed from or added to the directory hierarchy being searched it is unspecified whether or not find includes that file in its search.   Since it's unspecified whether new files will be included, maybe a safer approach would be  find dir -type d -exec sh -c '     for n in "$1"/*.txt; do         test -f "$n" &amp;&amp; mv "$n" "${n%.txt}_hello.txt"     done' sh {} ';'   Here, we don't look for files but for directories, and the for loop of the internal sh script evaluates its range once before the first iteration, so we don't have the same potential issue.  The GNU find manual does not explicitly say anything about this and neither does the OpenBSD find manual.
16378
Right now I have one-liner like this:  curl -fsSL http://git.io/vvZMn | bash   It is downloading script and passing it to bash as stdin file. I would like to run this script with additional argument print.  Maybe something like this?  curl -fsSL http://git.io/vvZMn | bash -- print   But this doesn't work.
75140
I have the following shell script that sums up all the arguments passed to it (space separated):  sum=0 for arg in "$@"; do     (( sum += arg )) done echo $sum   I have saved it as SumAll.sh. So, its supposed to function as follows:  sh SumAll.sh 2 4 6 8 20   or  bash SumAll.sh 1 -2 3 -3 -1   Both work on my local machine (MacBook), but when I try the same in a linux server, running the script with bash works, but with sh does not work. I get the following error:  sum: '+=': No such file or directory sum: arg: No such file or directory   Why is that? And how do I fix it?
53288
myscript [-a a-arg] [-c c-arg] [-b] [-e] somedirectory   Given that I want my shell script be invoked at the command line using the above parameters - where [these brackets] denote that they are optional - what is the best method to parse them?
67692
INPUT_FILE=`ls -rt $MY_DIR/FILE.*.xml | head -1 | xargs basename`   I wanted to execute the second command (head -1) only if the first command is successful. How do I improve this command?
112657
I know I can solve this problem several ways, but I'm wondering if there is a way to do it using only bash built-ins, and if not, what is the most efficient way to do it.  I have a file with contents like  AAA B C DDD FOO BAR   by which I only mean it has several lines and each line may or may not have spaces.  I want to run a command like  cmd AAA "B C DDD" "FOO BAR"   If I use cmd $(&lt; file) I get  cmd AAA B C DDD FOO BAR   and if I use cmd "$(&lt; file)" I get  cmd "AAA B C DDD FOO BAR"   How do I get each line treated a exactly one parameter?
48712
I am new to bash script programming.  I want to implement a bash script 'deploymLog', which accepts as input one string argument(name).  [root@localhost Desktop]# ./deploymLog.sh name   here I want to pass the string argument(name) through command line   As an initial step, I need to append the current timestamp along with this input string to a log file say Logone.txt in current directory in the below format:  [name]=[System time timestamp1]   How it is possible?
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?
98480
I want to find all files, and print the path and filename, for any file where the text "Numlock" is used - whether it is lower-, upper- or mixed-case.  What command should I use ?
81295
Is there any easy way to pass (receive) named parameters to a shell script?  For example,   my_script -p_out '/some/path' -arg_1 '5'   And inside my_script.sh receive them as:  # I believe this notation does not work, but is there anything close to it? p_out=$ARGUMENTS['p_out'] arg1=$ARGUMENTS['arg_1']  printf "The Argument p_out is %s" "$p_out" printf "The Argument arg_1 is %s" "$arg1"   Is this possible in Bash or Zsh?
28963
I thought this would be simple - but it is proving more complex than I expected.  I want to iterate through all the files of a particular type in a directory, so I write this:  #!/bin/bash  for fname in *.zip ; do    echo current file is ${fname} done   This works as long as there is at least one matching file in the directory. However if there are no matching files, I get this:  current file is *.zip   I then tried:  #!/bin/bash  FILES=`ls *.zip` for fname in "${FILES}" ; do     echo current file is ${fname} done   While the body of the loop does not execute when there are no files, I get an error from ls:  ls: *.zip: No such file or directory   How do I write a loop which cleanly handles no matching files?