so, i'm going to check whether a directory exists or not, if not, then the script is going to create one. and here is the code:  APPLICATION_DATA_DIRECTORY="~/.directorychecker/" APPLICATION_DATA_DIRECTORY_CREATE="~/.directorychecker/" CHECK_APPLICATION_DATA_DIRECTORY() {     if [ -d "$APPLICATION_DATA_DIRECTORY" ]     then     echo "directory exists"     else     mkdir $APPLICATION_DATA_DIRECTORY_CREATE     echo "directory is NOT exist, but now created"     fi }   CHECK_APPLICATION_DATA_DIRECTORY   however, while the folder check mechanism runs smoothly, the folder creation mechanism don't want to run and returns  mkdir: cannot create directory `~/.directorychecker/': No such file or directory   i really got no idea on making it work since the script seems fine  does anybody here had the same problem and solution? any answer will be appreciated  Thanks
121539
Here is my script:  #!/bin/bash  echo "Digite o local em que deseja instalar o IGRAFU(pressione enter para  instalar em  ${HOME}/IGRAFO):" read caminho if test -z $caminho then caminho="${HOME}/IGRAFO" fi echo "O IGRAFU será instalado no diretório: $caminho" mkdir -pv $caminho  mv -v ./* $caminho echo "Pronto!"   At 'read caminho' I may receive from the user a path like ~/somefolder. When the script receives that kind of path both mv and mkdir won't make tilde expansion, so it will try to create a ~/somefolder and not /home/username/somefolder and therefore fail.  How do I ensure that the tilde will be converted into the HOME variable?
96219
I was playing around in a shell and typed ./. I go the following output:  bash: ./: Is a directory   It looks like "./" checks if a directory with the given name exist. I was trying to find documentation on this to see if my understanding was right, but can't find anything online. Can anyone explain this one to me?
29907
I was trying to write a shell script that will take a directory path d as an argument and recursively print a depth indented list of all files and directories in d. However, the argument d is optional and if no argument is given, a depth indented list of all files and directories​ ​in​ ​the​ ​current​ ​ directory​ will​ ​be printed. Here is my code: # the method for tree  myspace=&quot;&quot; spaceCount=0 tree(){        cd &quot;$1&quot;   for i in *; do     if [ -d &quot;$i&quot; ]; then       echo -n &quot;|&quot;          for (( j=0;j&lt;spaceCount;j++ ))        do          echo -n &quot;$myspace&quot;         done       echo &quot;--$i&quot;       spaceCount=$((spaceCount+1))        myspace=&quot;  |&quot;       tree &quot;$i&quot;     else       echo -n &quot;|&quot;       for (( j=0;j&lt;spaceCount;j++ ))        do          echo -n &quot;$myspace&quot;         done       echo &quot;--$i&quot;     fi   done   cd ../   spaceCount=$((spaceCount-1)) }   if [ &quot;$1&quot; != &quot;&quot; ]; then   file=&quot;$1&quot; fi echo &quot;.$file&quot; tree &quot;$file&quot;  But when a folder is empty, it's printing a star like this: How can I solve the problem?
91310
I'm currently working on a plugin, and I essentially want to check if a certain page has been created.  Essentially, I want to do something like this:      if (file_exists($file)) {     $exists = true; } else {     $exists = false; }   But I just want to do it so that it checks, instead, for a post_name value. (If I was further able to ensure that the post was a page and not just a post with that title, that would be great too.)  How do I do this?  I had been getting the script to grab the headers from the url of the post and if it returned a 404, to return $exists = false, but I've pinpointed a memory leak problem with that and I don't think it's very efficient.
45294
The situation is:  I have a shared directories from many other machines where other users work on.  I need to be notified whenever a user create, modify or delete a directory or file from his local directory which I share using smb...  It looks like the folder actions in the MAC systems..  Is there a software that do that?!  If there is no such application, any help in writing a script for that is appreciated..  Thanks in advanced...
110327
I have separate scripts for tasks in bash. Here is the broken one:  #!/bin/bash PATH=/home/name/ mkdir $PATH cd $PATH &amp;&amp; echo "done." exit 0   Today it broke and first time it simply didn't want to run cd, but created directory. Second time it just said "mkdir command not found." Running this commands exactly with semicolon works fine. What the case?
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.
95760
Just noticed it works on Maverick.. the colon character : is valid for file and directory names (I accidentally entered it for a filename in Atom).  Can't find any reference to it becoming valid though ( still marks it as invalid).  It works in the Atom editor.  I can create a file called : with nano.  This works echo 'test' &gt; : &amp;&amp; cat :  In TextWrangler it only works if the file already exists but won't create it (with command line tools installed edit :)  Is this new from Mavericks? Works in Yosemite? Before?  Edit: A few more tests:    TextEdit won't allow me to enter it and always replace it with - Finder won't allow me to create a folder with the name :  A : file created via command line is displayed as / in Finder.. and double clicking it will open it in TextEdit. TextEdit will load its content but show the name / in the title bar.
38314
touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\') 2&gt; /dev/null   where foo is a directory  It's reading the full pathname of foo and creating it as a file replacing all '/' with '\' and putting a directory_ in front so the directory  /home/test/foo would create a file directory_\home\test\foo  It does exactly what I want except a warning keeps printing tr: warning: an unescaped backslash at end of string is not portable   a. I don't know what that means b. I would like it to not show  I tried to redirect stderr to /dev/null but it doesn't work. How do I suppress it?
72629
Let's say the directory ~/this_dir doesn't exist.  I need to be able to run touch ~/this_dir/new.txt to create new.txt in ~/this_dir.  Is there a simple way to make touch also create the directory?  Or an alternative command which would achieve the same thing?  Thanks
100532
The runtime arguments are as follows: $1 is the path to the file containing the list of files $2 is the path to the directory containing the files What I want to do is check that each file listed in $1 exists in the $2 directory  I'm thinking something like:  for f in 'cat $1' do if (FILEEXISTSIN$2DIRECTORY) then echo '$f exists in $2' else echo '$f is missing in $2' sleep 5 exit fi done   As you can see, I want it so that if any of the files listed in $1 don't exist in the directory $2, the script states this then closes. The only part I can't get my head around is the (FILEEXISTSIN$2DIRECTORY) part. I know that you can do [ -e $f ] but I don't know how you can make sure its checking that it exists in the $2 directory.
93240
I'm looking for a script that counts files in the current directory (excluding sub directories). It should iterate through each file and if not a directory increment a count. The output should just be an integer representing the number of files.  I've come up with  find . -type f | wc -l   But I don't really think it does the whole counting bit. This is for an assignment so if you only want point me in the right direction that would be great.
103118
In Linux shell, am I able to create a directory but the name would be a string returned from another program? And if I am able, how to?  In particular I am asked to create a new directory in my Home, and its name would be the minute on my computer's clock. Let's suppose /home/john/01/, 01 is the minutes on my clock.  I was thinking something like pipeline date +"%M" | mkdir but I do not know how I am gonna put that returned number into the mkdir program.  Finally another idea came to my mind, something like this mkdir (date +"%M") but this as well is a mistake. Any help please?
17861
How would I validate that a program exists, in a way that will either return an error and exit, or continue with the script?  It seems like it should be easy, but it's been stumping me.
122854
I wrote a script for the purpose of changing directory and then scan a file.  #!/bin/bash model_dir=/mypath  function chdir () {   cd $1 } chdir ${model_dir}/config if [[ ! -s *.cfg ]] then   echo `date` "configure file does not exist"   exit 1 fi   I don't why my current directory is not changed after I execute this script with source myscript.sh.
69958
I am reading through a directory with some pictures and such using a pretty simple implementation of readdir() like the following:  if ($handle = opendir($path)) {     while (false !== ($szFilename = readdir($handle))) {     if ($szFilename[0] !== '.') {         if (is_file($path.$szFilename)) {                 // do stuff             }         }      }  }   The problem that I am having is that the files are not being read in alphabetical order as the docs for readdir() state:     Returns the filename of the next file   from the directory. The filenames are   returned in the order in which they   are stored by the filesystem.   Another weird thing is that, on the local testing server, the same code works great.  This is running on a server using the LAMP stack in both cases.  I know that I can build an array and just sort it, but I was wondering if I was missing something in what I was doing.
82471
I've installed a version of Ubuntu Server and although I'm fairly still fresh with Ubuntu, I'm trying to create a bash file to run a program in the background. More importantly, I'm trying to get a file nameto display correct and create it before I start running the program (I like my debug stuff).  However, here is my bash script:    #!/bin/bash  PATH="/var/log/servers/Game/"  FILENAME="startup"  EXT=".log"  DATE=$(date +%d-%m-%Y)  NEWFILE=${PATH}${FILENAME}_${DATE}${EXT}   I have verified that the file does exist in the PATH directory. However, the issue is with the date command. When I run the script bash -x game.sh this is what is displays.   + PATH=/var/log/servers/Game/  + FILENAME=startup  + EXT=.log  ++ date +%d-%m-%Y  game.sh: line 5: date: command not found  + DATE=  + NEWFILE=/var/log/servers/Game/startup_.log  + echo /var/log/servers/Game/startup_.log   I don't understand why it would say the command doesn't work, when I can go to the main console and run date and get a valid response.  Any help is greatly appreciated!