I want to call a function ONLY when the file name ends with .request but somehow it calls the function if request is sub-string.  I  the imported parts, on the right it's the output  for file in ${filesOrDir[*]}; do         if [[ -f "$file" ]]; then         if [[ "$file"=*[".request"] ]]; then             # Enters here when .request is a substring.         fi     fi     if [[ -d "$file" ]]; then             # ... some logics            fi done
102550
I am writing a nightly build script in bash. Everything is fine and dandy except for one little snag:   #!/bin/bash  for file in "$PATH_TO_SOMEWHERE"; do       if [ -d $file ]       then               # do something directory-ish       else               if [ "$file" == "*.txt" ]       #  this is the snag               then                      # do something txt-ish               fi       fi done;   My problem is determining the file extension and then acting accordingly.  I know the issue is in the if-statement, testing for a txt file.    How can I determine if a file has a .txt suffix?
111364
Some guy called one of my Snipplr submissions "crap" because I used if ($_SERVER['REQUEST_METHOD'] == 'POST') instead of if ($_POST)  Checking the request method seems more correct to me because that's what I really want to do. Is there some operational difference between the two or is this just a code clarity issue?
60818
I need to test if a file is a shortcut. I'm still trying to figure out how stuff will be set up, but I might only have it's path, I might only have the actual contents of the file (as a byte[]) or I might have both.  A few complications include that I it could be in a zip file (in this cases the path will be an internal path)
26539
find . -name *.jks -print 2&gt;/dev/null   returns files of extension jks that do not have underscores as part of their name.  Much to my surprise, I have just discovered that * does NOT substitute the underscore.  find . -name *_*.jks -print 2&gt;/dev/null   returns files of extension jks that have one underscore.  How do I search for files that have 0 or more underscores?  Using OSX Mountain Lion.
18973
I need to write a function that receives a string and a regex. I need to check if there is a match and return the start and end location of a match. (The regex was already compiled by qr//.)  The function might also receive a "global" flag and then I need to return the (start,end) pairs of all the matches.  I cannot change the regex, not even add () around it as the user might use () and \1. Maybe I can use (?:).  Example: given "ababab" and the regex qr/ab/, in the global case I need to get back 3 pairs of (start, end).
60654
The question is about special variables. Documentation says:     !!:$      designates the last argument of the preceding command. This may   be shortened to !$.        ($_, an underscore.) At shell startup, set to the absolute pathname used  to invoke the shell or shell script being executed as passed in the    environment or argument list. Subsequently, expands to the last argument to the previous command after expansion. Also set to the full pathname  used to invoke each command executed and placed in the environment    exported to that command.    There must be some difference I cannot catch, because:  $ echo "hello" &gt; /tmp/a.txt $ echo "!$" echo "/tmp/a.txt" /tmp/a.txt  $ echo "hello" &gt; /tmp/a.txt $ echo $_ hello   What is the difference?
73904
When is it a good idea to use ?  I sometimes see this in code samples of PHP. Does this handle DOS/Mac/Unix endline issues?
20165
I have written a simple script.  When I runsh &lt;myscriptname.sh&gt;, i got the correct output, but when I run ./&lt;myscriptname.sh&gt;, I got an error.  What is difference between when I do sh and ./?
4188
While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:  flist = []  for i in xrange(3):     def func(x): return x * i     flist.append(func)  for f in flist:     print f(2)   Note that this example mindfully avoids lambda. It prints "4 4 4", which is surprising. I'd expect "0 2 4".   This equivalent Perl code does it right:  my @flist = ();  foreach my $i (0 .. 2) {     push(@flist, sub {$i * $_[0]}); }  foreach my $f (@flist) {     print $f-&gt;(2), "\n"; }   "0 2 4" is printed.  Can you please explain the difference ?    Update:   The problem is not with i being global. This displays the same behavior:  flist = []  def outer():     for i in xrange(3):         def inner(x): return x * i         flist.append(inner)  outer() #~ print i   # commented because it causes an error  for f in flist:     print f(2)   As the commented line shows, i is unknown at that point. Still, it prints "4 4 4".
112947
To make it short, doing something like:  -bash$ function tt {  echo $0; }  -bash$ tt   $0 will return -bash, but how to get the function name called, i.e. tt in this example instead?
117426
Why when I try to write a function just in one line into .bashrc file,  list(){ ls -a }   I get error?  bash: /home/username/.bashrc: line num: syntax error: unexpected end of file   but when I write it in multi line it's ok?  list(){     ls -a }
55501
I tried searching previous questions but none worked, or I couldn't adapt them to my needs.  I want to write a script that asks for:   folder criteria old string new string   And replace every file in the specified folder and subfolders (and force user to type one) with specific criteria (for example, it must be a ".cue" file), and:   If the file is read-only, disable it. Search for specified old string in the file content and replace it with new string , and save changes in same file. If the file was read-only, enable it again.   I have this code so far, but I don't know what to do in the do part:  @echo off   setLocal enableDELAYedexpansion  :START set "var2=" set /P var2="type folder "  if "%var2%"=="" goto ERROR  set /p old="old string ? " set /p new="new string ? " set /p files="what criteria ? " echo modifying files...  for /r "%var2%" %%v in (%%files) do (  ???  ) pause  goto START  :ERROR echo type something!! goto START
116874
I want to count the total number of files in particular directory that ends with ".mp4" extension.  I am getting following command:  ls -F |grep -v / | wc -l   It count all the files in particular directory, but I want the count of files that end with .mp4 extension.  Is there any Ubuntu command for that?
10610
I have a url like   I need a javascript function to give me the 'th' value from that.  All my urls have the same format (2 letter filenames, with .html extension).  I want it to be a safe function, so if someone passes in an empty url it doesn't break.  I know how to check for length, but I should be checking for null to right?
10337
Why do we use ./filename to execute a file in linux?  Why not just enter it like other commands gcc, ls etc...
26511
I’m looking for a trick about this. I know how to call a dynamic, arbitrary function in JavaScript, passing specific parameters, something like this:  function mainfunc(func, par1, par2){     window[func](par1, par2); }  function calledfunc(par1, par2){     // Do stuff here }  mainfunc('calledfunc', 'hello', 'bye');   I know how to pass optional, unlimited parameters using the arguments collection inside mainfunc, but, I can’t figure how to send an arbitrary number of parameters to mainfunc to be sent to calledfunc dynamically; how can I accomplish something like this, but with any number of optional arguments (not using that ugly if–else)?  function mainfunc(func){     if(arguments.length == 3)         window[func](arguments[1], arguments[2]);     else if(arguments.length == 4)         window[func](arguments[1], arguments[2], arguments[3]);     else if(arguments.length == 5)         window[func](arguments[1], arguments[2], arguments[3], arguments[4]); }  function calledfunc1(par1, par2){     // Do stuff here }  function calledfunc2(par1, par2, par3){     // Do stuff here }  mainfunc('calledfunc1', 'hello', 'bye'); mainfunc('calledfunc2', 'hello', 'bye', 'goodbye');
123524
I performed an ls -la on directory on my CentOS 6.4 server here and the permissions for a given file came out as:  -rwxr-xr-x.   I understand what -rwxr-xr-x means, what I don't understand is the . after the last attribute.  Can someone explain it to me? Is it harmful in any way? Can it be removed?