Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mkdir always creates a file instead a directory

Tags:

bash

mkdir

First I want to say that I don't really know what I should look for, here in Stack Overflow and what could be a good query for my problem.

In simple words I want to create a new directory and than do some file operations in it. But with the script that I have crafted I got always a file instead of a directory. It seems to be absolutely regardless how I stick the code together there is always the same result. I hope tat masses can help me with their knowledge.

Here is the script:

#!/bin/bash

 DLURL=http://drubuntu.googlecode.com/git'
 d7dir=/var/www/d7/'
 dfsettings=/var/www/d7/sites/default/default.settings.php
 settings=/var/www/d7/sites/default/settings.php

#settiing up drush
drush -y dl drush --destination=/usr/share;  

#Download and set up drupal
cd /var/www/;
drush -y dl drupal;

mkdir "$d7dir"; #this is the line that always produces a file instead a directory
                # regardless if it is replaced by the variable or entered as         
                # /var/www/d7


cd /var/www/drup*;
cp .htaccess .gitignore "$d7dir";
cp -r * "$d7dir";
cd "$d7dir";

rm -r /var/www/drup*;
mkdir "$d7dir"sites/default/files; 
chmod 777 "$d7dir"sites/default/files;  
cp "$dfsettings" "$settings";
chmod 777 "$settings";
chown $username:www-data /var/www/d7/.htaccess;
wget -O $d7dir"setupsite $DLURL/scripts/setupsite.sh; >  /dev/null 2>&1
chmod +x /var/www/setupsite; 
echo "Login Details following..."; 
read -sn 1 -p "Press any key to continue...";
bash "$d7dir"setupsite;
chown -Rh $username:www-data /var/www;
chmod 644 $d7dir".htaccess;
chmod 644"$settings";
chmod 644"$dfsettings"; 
exit

I hope someone got the reason for that.

like image 781
Josh Avatar asked Mar 06 '26 18:03

Josh


1 Answers

There are many way to debug a shell-scripting.

  • Add set -x in your beginning script
  • Get the return value.

    mkdir 'the-directory'
    ret=$?
    if test $ret -eq 0; then
        echo 'Create success.'
    else
        echo 'Failed to create.'
    fi
    
  • Set to verbose mode $ mkdir -v 'the-directory'

Try this command $ type mkdir, to checking mkdir command.

like image 103
emaniacs Avatar answered Mar 09 '26 14:03

emaniacs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!