[Solved] Shell: Is there a difference between / and // in directories?

Hello:
I'm making this tiny program in Shell:
# Function.
# NAME: chk_df
# Synopsis:
# Check if a local directory (dirName) exist and has a file (fileName).
# The return codes are the following:
# 99 : dirName does not exists
# 0 : dirName exists and has fileName
# 1 : dirName exists and has not fileName
# Parameters:
# In values: dirName <string> fileName <string>
# Out values: returnCode <int>
# How to use:
# chk_df dirName fileName
chk_df(){
# Check the number of arguments that could be passed.
# In this case, two, dirName, fileNAme.
if [[ ${#@} != 2 ]]; then
echo "Error ...Use [Funtion]: chk_df <dirName> <fileName>"
echo "Ex: chk_df /foo lola.txt"
exit
fi
DIR=$1
FILE=$2
[[ ! -d $DIR ]] && return 99
[[ -d $DIR && ! -e $DIR/$FILE ]] && return 1
[[ -d $DIR && -e $DIR/$FILE ]] && return 0
Because I need to check if a file is in a directory, I did this (horrible?) patch $DIR/$FILE , but things like this could happen:
I) If we do: chk_df /foo lola.txt
We get: /foo/lola.txt
II) If we do: chk_df /foo/ lola.txt
We get: /foo//lola.txt [Notice the //]
In both cases the code seems to work. Why?
Could I leave it like that or it will bring problems? Is there a difference? UNIX assume it to the right way?
EXTRA QUESTION: why I can not do the returns with negative numbers? This is:   return -1
Thank you.
Last edited by gromlok (2011-11-07 15:48:44)

If this script is bash only, you could use bash parameter expansion to get rid of any number of //:
$ DIR="/long//numerous//doubleslashed/path/to/"
$ FILE="file"
$ MYPATH="$DIR/$FILE"
$ cd $MYPATH
bash: cd: /long//numerous//doubleslashed/path/to//file: No such file or directory
$ cd ${MYPATH//\/\//\/}
bash: cd: /long/numerous/doubleslashed/path/to/file: No such file or directory
See http://mywiki.wooledge.org/BashGuide/Pa … _Expansion if you want a better explanation.
Edit: changed variable name from PATH to MYPATH.  Boy was I surprised by bash: pacman: command not found
Last edited by alphaniner (2011-11-07 17:26:02)

Similar Messages

  • Is there a difference between SPDIF Optical and Digital Optical

    i want to connect my tv's audio output to my home theater
    i have a vizio tv, on the back of it, it says SPDIF OPTICAL OUT
    and on the back of my panasonic home theater system it says, DIGITAL AUDIO IN, i tried connecting an optical cable and the sounds from my won't still go through the home theater system speakers.
    i'm just wondering, is there a difference between SPDIF OPTICAL and DIGITAL OPTICAL?
    ports look like the same.
    Solved!
    Go to Solution.

    smileemile wrote:
    i want to connect my tv's audio output to my home theater
    i have a vizio tv, on the back of it, it says SPDIF OPTICAL OUT
    and on the back of my panasonic home theater system it says, DIGITAL AUDIO IN, i tried connecting an optical cable and the sounds from my won't still go through the home theater system speakers.
    i'm just wondering, is there a difference between SPDIF OPTICAL and DIGITAL OPTICAL?
    ports look like the same.
    Nope, two names for the same thing.
    You may have to change some settings of either the TV or the Panasonic system to output to the optical port (TV) and input from the optical port (surround receiver).
    *disclaimer* I am not now, nor have I ever been, an employee of Best Buy, Geek Squad, nor of any of their affiliate, parent, or subsidiary companies.

  • Is there a difference between the mw600 and mw600s

    Hi,
    I was wondering is there a difference between the stereo Bluetooth headset MW600S http://store.sony.com/webapp/wcs/stores/servlet/ProductDisplay?catalogId=10551&storeId=10151&langId=...
    and the MW600 like here http://www.amazon.com/Sony-1264-5582-MW600-Wireless-Headset/dp/B008NA985C/ref=cm_cr_pr_product_top
    Thanks
    Solved!
    Go to Solution.

    Hello ERGIC53,
    The model numbers that you are referring to are for the Sony Ericsson Stereo Bluetooth headsets. Sony Mobile phones have their own separate community and so are best qualified to address any issues or questions you may have on Sony mobile phones. You can visit the Sony Mobile Community here.
    http://talk.sonymobile.com/community/support
    If my post answers your question, please mark it as an "Accepted Solution."

  • Is there a difference between a Hot Backup and an Online backup?

    Version:10g2
    Is there a difference between a Hot Backup and an Online backup? Aren't these terms interchangeably used? Couldn't find a similair thread in OTN.

    They mean same meaning. They are synonyms in Oracle language :)
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • Is there any difference between amd 7640m 1GB and amd 7670m 2GB graphics performance...?

    Hello experts,
                              I have a question regarding laptop gaming performance.
    I have HP Pavilion G6 2005ax with AMD 7640g + 7670m (1.5 GB) graphics. But gaming performance is not awesome. It's not capable to run latest PC game at highest settings.
    My question is that Is there any difference between AMD 7640g + 7670m (1.5 GB) and AMD 7640g + 7670m (2.5 GB) graphics cards performance...?
    One graphics card hase 7670m 1GB and second one has 7670m 2GB graphics RAM.
    So which one perform better and why....?
    Should I upgrade AMD 7670m 1GB to AMD 7670m 2GB to play latest pc games at highest settings.....?
    Netbook configuration----- 
    HP Pavilion G6 2005AX
    AMD A-8 4500m processor
    4GB RAM
    AMD 7640g + 7670m (1.5 GB)
    5ooGB HDD

    CSsingh wrote:
    .... One graphics card hase 7670m 1GB and second one has 7670m 2GB graphics RAM. So which one perform better and why....?
    Hi,
    Same GPU but more RAM will perform better. You have to make decision before hand, upgrading it is a pain.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Is there any difference between R/3 4.7 version and ECC 5.0????

    Hi All,
      Is there any difference between R/3 4.7 version and ECC 5.0 for the transaction RSA5.
    Regards,
    Andy

    Andy
    Functionality wise I didn't see any difference other than new datasources in ECC5.0
    Thnaks
    Sat

  • Is there a difference between microsoft office for mac and for windows?

    As a college student it's important that everything is equal for windows and mac for using instructions. So i am wondering if theres a difference between microsoft office for mac and for windows?

    There are differences between the two version of Office. If you need to be exactly like the Windows version, you will have to run Windows on your Mac.
    Allan

  • I did re-set my password and when I click on Install for Mavericks, I still get a box for "administrator password" and it still won't accept my new password. Is there a difference between my Apple ID and the administrator password they're asking for?

    I downloaded Mavericks and it won't install. I did re-set my password and when I click on Install for Mavericks, I still get a box for "administrator password" and it still won't accept my new password. Is there a difference between my Apple ID and the administrator password they're asking for? I never had an administrator password-- I just hit enter and have never had a problem before with previous installations. I'm on an iMac, from 2007, running Mt. Lion (version 10.8.5). I've been looking for other's posts who may be having the same problem, but haven't found any. Can anyone help?

    Ugh. The 'no password, no work' thing is a recent Apple development. I ran into it on my system and ended up having to do a clean install on a partition I fully erased.
    I suppose, if you have the ability to, go online and look up how to burn a bootable DVD image. Download the 10.8.4 image then use the Disk Utility to make a boot image of it. You'll need a dual-layer DVD or a USB drive (or memory stick at least 8GB) If you've got an optical drive, burn the disk, if you've a USB device, use that.
    Then get a pocket drive and copy your important files off the system or let Time Machine do a full backup.
    When the backup is done, insert the disk and hold down the C key until the machine boots off of the DVD. At the point you get to the start window, go to the menu and choose the Disk Utility.
    In the Disk Utility, reformat the drive. You go to the actual DRIVE (not the Macintosh HD, but the root above it that is the actual hard drive device)
    I always do this and *partition* it into several volumes, the benefit being, you can store all of your music, documents and importans stuff on that secondary storage volume you make - it will have it's own index and then the first volume is where you put the OS and it will have it's own index as well. That way, if the OS throws a wobbler and you need to reinstall, you don't lose your data.
    Depending on the size of your hard drive, it is good to give your OS partition at least 60GB and optimally 100GB, and the rest for storage.
    Name your volumes, use the little box sliders to manually size them or put that number in the size window, select for the format, Mac OS Extended (Journaled) and hit Apply and then the Disk Utility will quickly create your new partitions.
    Once finished, quit the Utility and it will return you to the OS installer. Select the volume you want to install to and it should start up and install.
    Once the installation is done, you'll get the new machine startup then you MUST put in a password for the computer. Once you're in, and to the desktop, don't bother with any Mountain Lion updates, go right to the App Store and get the Mavericks update and let it install the app to your Applicaitons folder, then do that install.
    On a side note, there MAY be a way to make a disk image from the Mavericks application and avoid the entire Mountain Lion step.. I honestly do not know, but a bit of hitting the search engines may find out if there is. I think that if you looked for "make Mavericks boot disk or boot image' you may find something.
    Good luck!

  • Is there a difference between Adobe Photoshop 7.0 and Adobe Photoshop Elements 7.0?

    Is there a difference between Adobe Photoshop 7.0 and Adobe Photoshop Elements 7.0?

    Yes: (these are just general differences, not specific to either photoshop 7 or photoshop elements 7)
    (photoshop elements does offter one thing not mentioned that photoshop 7 doesn't have, a camera raw plugin that doesn't cost extra)
    (photoshop elements 10 and photoshop cs5 are the current versions)
    http://simplephotoshop.com/photoshop_elements/photoshopelements_vs_photoshop.htm
    http://graphicssoft.about.com/cs/photoshop/f/elementscompare.htm

  • Is there a difference between Lightroom CC  and  Lightroom 5.7?

    Is there a difference between Lightroom CC  and  Lightroom 5.7? If so, is the upgrade from Lightoom 5.7 to  Lightroom CC for free?

    Yes the two programs are different. Lightroom CC has a number of new features added to it. They include HDR and panorama creation, brushes for the graduated filter and the radial filter, face recognition, support for new cameras, just to mention a few. Lightroom CC is a free upgrade for those who have subscribed to the creative cloud plan. Lightroom 6 (the standalone version) is a paid upgrade. The price is $79.

  • Is there a difference between the Ethernet WAN port and the other 3 Ethernet Ports on a Time Capsule?

    As posted previously, my time capsule will not set up properly because I get an IP address conflict pop up window.  Is there a difference between the "Ethernet WAN Port" and the other three ports on the back of the Time Capsule?  I may have the DSL modem hooked into the "Ethernet WAN Port".  Thanks.

    it depends what you want to achieve and what configuration you have on your DSL modem/router.
    Resetting TC and run connection wizard from the Airport utility.
    Post the problems.

  • HT1604 Is there any difference between Mac OS Extended Format and ExFat?

    Is there any difference between Mac OS Extended Format and ExFat?  I read in a blog that the ExFat was a good way to format an external drive because it avoided many of the pitfalls of the other formats, as long as it is supported by the operating system.  I tried to format my new Seagate drive, and got an invalid option error.  I was able to format it in Mac OS Extended format.  Can you please tell me if this is similar to ExFat.  Thanks.

    The Mac OS format can only be natively read to and written to by a computer running the Mac OS. This creates a problem if the user wishes his external, or other drive to have seamless compatibility between two different OS's, such as Windows and Mac. Yes, there are software solutions that enable a Windows PC to work with a drive formatted as Mac OS, but it gets complicated if you wish that drive to have compatibility "on the fly" with any PC you may encounter.
    It turns out that the format known as ExFAT is able to be natively read by both a Mac and a PC, without running any additional drivers on either machine. ExFAT also doesn't have some of the limitations of FAT32, which both OS's will also read/write.
    ExFAt is not perfect though. Formatting the drive as Mac OS Extended has some advantages on a Mac. First, it is the only format that permits all functionality of the Mac OS, such as using the drive for Time Machine.
    ExFAt is often thought of as the best middleground for an external partition/drive that needs to have easy cross platform compatibility between a Mac and  PC running Vista or Windows 7.

  • Is there Any difference Between OBPM 10g And AlBPM 6.0

    Hello Friends
    I would like know is There any difference between the Oracle BPM 10g and ALBPM 6.0 . ??
    The second one is Difference between AlBPM5.7 and ALBPM 6.0
    Thanks In Advance
    with Regards
    Sandeep
    Edited by: user12036530 on Oct 18, 2009 9:08 PM

    For 10g Differences, check out: http://download.oracle.com/docs/cd/E13154_01/bpm/docs65/upgradeguide/deliverables/upgrade_guide/c_Head_Reference.html
    And other 10g Documentation: http://download.oracle.com/docs/cd/E13154_01/bpm/docs65/index.html Specifically: Upgrade Guide, Process API Differences (if you use PAPI)
    For 6.0 Differences, check out the Documentation: http://download.oracle.com/docs/cd/E13165_01/albsi/docs60/index.html Specifically: ALBPM 6.0 New Features Overview
    Hope this helps,
    -Kevin

  • Is there a difference between itunes and apple tv

    Sorry if this  has been asked before. Is there a difference between the content on iTunes and the content on Apple TV?
    I was searching for a movie today and found differing results to begin with between the iTunes on my phone and iTunes on my ipad2, this turned out to be the price for a SD version on my iPhone and the HD version found on my iPad2. However I searched for the same movie on Apple TV and couldn't find it, hence the why I am asking if there is a difference between what's available.

    Your Apple TV searches iTunes Store for either SD or HD but not both at the same time (you can change the default in settings), so if something isn't available in HD and you search using the HD default, you won't see it.

  • Is there a difference between the earphone output and the audio output of the docking connector, or is it in fact the same signal ?

    Is there a difference between the earphone output and the audiooutput of the docking connector of the iphone 4, or is it in fact the same signal ?

    One basic difference is that the LTE frequencies each is able to operate on are different. After that, it is pretty much the same phone. Others might be able to add to this.

Maybe you are looking for

  • I want only one apple ID for all my devices

    I have an apple ID and so does my wife.  Between the four family members we 8 plus apple devices.  I want to put everything on hers and just have one.  Mine has the least amount of music and apps.  Can it be done? How do you do it without losing anyt

  • Itunes wont download it gets close to finishing then wont download i have a windows 7

    can anyone help me i already downloaded it and uninstalled it and cleared the registry and it stilll will not download

  • Error when using WETextArea and WESubmitButton

    <p>Hi again,</p><p> </p><p>I think I may have found a issue.</p><p> </p><p>if you have a form that has only a WETextArea and a WESubmitbutton that is submitting back to the same report  ( with or with out database connection) I get a error message wh

  • Compressing attachments in entourage email

    I am unable to compress attachments in my entourage email. I have Stuffit Expander installed, and I still can't compress pictures and video. Is there something else that needs to be done?? Please help Powerbook G4   Mac OS X (10.4.6)  

  • Creating Data Source

    Hi Experts, While creating datasource,i am assigning it a view ( ZV_ZFT_CASHFLOW ) but following is error: Invalid extract structure template ZV_ZFT_CASHFLOW of DataSource ZFT_CASHFLOW      Message no. R8359 Diagnosis     You tried to generate an ext