How di I enter a sub-shell in a shell-function

Hi Community,
I'm searching for a quick and dirty solution to determine the folder size in a specific location. I tried to do this job in a for-loop but I ran into trouble with folders containing a space in it's name. So I changed the environment variable IFS (Internal Field Separator) to a new-line only instead the default whitespace. But after this I have to leave the shell to get rid of the user-defined IFS variable. Yes I could write the IFS variable in another (auxiliary) variable first to set it back to the default value after running the for-loop but this isn't a quick and dirty solution just for a short look to the folder size in a one line command.
So the one liner looks like:
IFS=$'\n' && for i in `ls`; do du -hs "$i"; done
With the result that the IFS variable changed for this session to a single new line. So I tried to define a shell-function who switch to a sub-shell, set temporary the IFS variable, run the for-loop and exit the sub-shell:
$ foldersize()
> {
> /bin/bash
> IFS=$'\n'
> for i in `ls`; do
> du -hs $i;
> done
> exit
> }
But running the function it only switch to the sub-shell and nothing more happens:
$ foldersize
bash-3.2$
So my question is how can I switch in a sub-shell using in a shell function?
Thx & Bye Tom

What is wrong with
du -hs *
if you want to call it 'foldersize' you can create an alias
alias foldersize='du -hs *'
If you really want to do your loop, you could try something like
foldersize()
    ls -1 "$@" | while read file
    do
        du -hs "$file"
    done
The 'while' loop is running in a sub-shell, so any shell variable changes made in the sub-shell will not be visible when you finish.  For that you could use the following notation:
foldersize()
    while read file
    do
        do -hs "$file"
    done <  <(ls -1 "$@")
Which will run the 'ls' in a sub-process and the 'while' loop will be run in the current shell invocation, and thus any shell variable changes made in the 'while' loop will be available when the loop finishes.
If you just want to do it your way, and do not need any shell variable changes returned to the invoking shell you could use:
foldersize()
    ( IFS=$'\n'
      for i in `ls "$@"`; do
        du -hs $i;
      done
Where everything inside the (...) will be run in a sub-shell, and all variable changes will not show up in the invoking shell.
Then again, you could have just put 'foldersize' in its own script file, made the file executable, and placed the script in $HOME/bin, then added $HOME/bin to your PATH environment variable, and when the script is invoked, it too will run in its own sub-shell.  Simple
#!/usr/bin/env bash
IFS=$'\n'
for i in `ls "$@"`; do
    du -hs $i;
done
The "$@" syntax says if there are any function arguments substute them here and preserve any white space.  The syntax includes the "..." as well as the $@.  All 4 characters need to be specified as "$@" to get the white space preserving effect.  And if there are no function arguments, then it is as if the 'ls' command was specified without additional arguments, as you have used it.  This gives you the ability to get the folder size of the current directory as well as specify any directory you choose.
NOTE:  All of the above should work as shown, most without the need for IFS
Message was edited by: BobHarris

Similar Messages

  • How can I enter my podcast in more than one category?  Mine covers arts, education and society and culture, but is listed as "Performing Arts".  Thank you for your time!

    How can I enter my podcast in more than one category, to reflect the fact that it covers arts, education and society and culture?  Thank you for your time!

    You can have more than one category - this page shows you how the tags are formed:
    http://www.apple.com/itunes/podcasts/specs.html#category
    The Store will list only the first category and its sub-category at the top of the page. Like the first category, the others will in theory make your podcast available for searching by category. However searching just on the category in the iTunes Store is most unlikely to throw up your podcast. There are thousands of podcasts out there, and it would be quite impossible to display on one page the entire list for any category. What you see are 'featured' podcasts, chosen by Apple as being special; please see this Tech Note:
    http://www.apple.com/itunes/podcasts/specs.html#getfeatured
    Note that there is no way you can influence the selection other than making your podcast really special.
    If you have further questions about making your podcast it's better to ask them in the Producing Podcasts forum.

  • How do  I enter fractions say  8 1/2  where the 1/2 becomes smaller asyou would  do in Word

    How do  I enter fractions say  8 1/2  where the 1/2 becomes smaller as you would  do in Word.Currently I use size 12 for main number and size 10 for the fraction.
    Any suggestions? I am using Framemaker 9.
    thanks
    Joe

    We do fractions as Variables. This works with any roman font. We do use the fraction slash (\xa4, auto-converted to §) from the Symbol set.
    Pre-requisite: make sure these Character Formats are defined:
    "Superscript" - as is except for [*] Superscript and [*] Pair Kern
    "Subscript" - as is except for [*] Subscript and [*] Pair Kern
    "Symbol" - as is except Font [Symbol] and [*] Pair Kern
    Typical Variables
    Name: fraction.500.one.half
    Definition: <Superscript>1<Default ¶ Font><Symbol>§<Default ¶ Font><Subscript>2<Default ¶ Font>
    Name: fraction.781.twenty_five.thirty_second
    Definition: <Superscript>25<Default ¶ Font><Symbol>§<Default ¶ Font><Subscript>32<Default ¶ Font>
    Doing it this way you aren't restricted to the pre-defined fractions in your fonts, or compelled to use a separate math/symbol font with a larger selection of fracs.
    You also avoid adjacent text being at risk of being rendered as super/sub. The frac is a single object, easily cut, copied and pasted without literal side effects.
    Including the decimal equivalent causes the pull-down menu list to self-sort.

  • Can't install Lightroom 5 on a second computer, I am NOT a creative cloud customer, I am a stand-alone user.  How do I enter my serial number???

    I can't install Lightroom 5 on a second computer, I am NOT a creative cloud customer, I am a stand-alone user.  But when I try to install on my laptop, it always trys to sell me the monthly membership.  How do I enter my serial number in the second copy of lightroom?  It won't ask me for it, and I cannot enter it anywhere in the settings?  I am stuck

    You probably downloaded the Cloud version.  Get the licensed version thru the following linked page...
    Lightroom - all versions
    Windows
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Windows
    Mac
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Macintosh

  • How do I enter an itunes U course code in iTunes on a PC? My teacher gave me a course code to enroll in their course (unpublished), but I don't have an iPad or iPhone. Can I use iTunes on my PC?

    How do I enter an iTunes U course code in iTunes on a PC? My teacher gave me a course code to enroll in their course (unpublished), but I don't have an iPad or iPhone. Can I use iTunes on my PC? I don't see a place to enter my enrollment code. I also tried using the link sent to enroll but it doesn't work either.  Am I out of luck?

    As I noted in the other thread:
    There are two kinds of content available, "courses" and "collections". If you look at the iTunes U section on the iTunes Store, you'll note some are square (collection) and some have a faux wire binder and tabs (course); you can subscribe and watch collections from within iTunes, but courses only work on iOS.
    The content you see in iTunes on your PC are "collections", while your teacher has created a "course". Collections are more like podcasts, with only audio or video episodes available. Courses have more structure and richer content, including assignments and iOS-specific materials like App Store links and Pages documents.
    While the distinction is not particularly relevant for iOS users – one can subscribe to either type – it is admittedly confusing for desktop users since the distinction and terminology are not explicitly defined.
    Does that clarify matters somewhat?

  • How do I enter music from MacBook to 2 GB memory card in my LG Dare

    How do I enter music from MacBook to 2 GB memory card in my LG Dare? I formatted the SanDisk memory card to the phone and connected phone to MacBook. How do I get music from iTunes on my MacBook to disk on my Dare?

    Look in the Finder's sidebar or on the desktop. If the manufacturer only allows its own software to connect to the card, consult its documentation.
    (55914)

  • HT1212 I just updated my Ipad 2 to IOS7, now it is asking me for a passcode. I never set a passcode on my Ipad, so how can I enter a passcode. I tried using the OIS7 passcode I use on my Iphone  and it did not work and now my Ipad is disabled

    I just updated my Ipad 2 to IOS 7, now it is asking me for a passcode. I never set a passcode on my Ipad, so how can I enter a passcode. Earlier today I upgraded my Iphone 5 to IOS 7 and it asked me to set a passcode, which now works fine on my Phone. I  tried using the OIS7 passcode I use on my Iphone 5 and it did not work and now my Ipad is disabled. Both devices are on icloud and share the same apple id. The Ipad screen says slide to set up but then there is a prompt for passcode, not for setting up passcode

    I called Apple Support and a supervisor helped resolve this for me on my iPad. I suggest calling them for help as this is obviously an issue with the iOS 7 update - she helped me without charge. I could be missing something in my upcoming description, so do not take this as complete - call them.
    I had to update iTunes on my Mac Air to the latest version, and I had an iCloud backup from the day I updated to iOS7. Have iTunes open but do NOT connect your iPad yet. Shut down the iPad. Then press/hold the Home key on the iPad while you connect the USB from the iPad to the computer (an image of the USB cable appeared on the iPad). Follow the prompts in iTunes to restore and then backup using iCloud. When the iPad rebooted again to do the backup install, I got the same pass code issue and iTunes would not recognize the iPad without entering a pass code. I disconnected the iPad, turned it off, pressed the Home key while connecting the USB cable. When I did the restore and backup from iCloud the second time, it worked without the pass code issue occurring.

  • How do I enter multiple email addresses for a Firefox Sync account?

    How do I enter my multiple email addresses for one Firefox Sync account?

    Sorry, but Address Book does not allow you to select more than one email address to send to in a group. There's really no reason why people need multiple copies of a message, anyway; they have the option of forwarding email to another email address of theirs.
    Mulder

  • How can I enter data in an input schedule on a member in the EPM Add-On that is not a base member?

    Hello, all,
    how can I enter data in an input schedule on a member in the EPM Add-On that is not a base member?
    E.g. I want to implement a top-down-planning scenario and I have the following hierarchy:
    Europe
         Germany
         France
         UK
         Spain
         Italy
    How can I enter a value on Europe in an input schedule in order to allocate this value afterwards?
    Thanks in advance and best regards
    Gerd

    Gerd,
    It should be something like below -
    EuropeInput
    Europe
         Germany
         France
         UK
         Spain
         Italy
    EuropeInput shall be kept out of hierarchy and should be a base level member. Users will enter the numbers in this member. In your script logic, you will make use of this member to allocate the data in Bas(Europe) i.e. Germany, France, etc.
    Effectively, after allocation the same data will be rolled up to Europe.
    Many top-down planning would use such work-around as BPC doesn't allow writing to parent node.
    Regards,
    Ashish

  • I have forgotten my password, how I can enter and generate a new one

    I have forgotten my password,how I can enter and generate a new one

    Try here.
    http://support.apple.com/kb/HE36?viewlocale=en_US&locale=en_US

  • I have changed my credit card. How can I enter my new credit card data to purchase Apps or iTunes music? Thanks. Philippe

    I have changed my credit card. How can I enter my new data to purchase Apps and music on i Tunes? Thanks. Philippe

    Tap  -  Settings/iTunes & App Store/Apple ID
    In the next window tap view Apple ID and enter password and click okay.
    You are now securly linked to your itunes account - tap Payment information and change the credit card details and then done/done.

  • My ipad has gone in lost mode by mistake and now i have it and i enter the password and i cant enter my ipad how can i enter or restart the ipad and start back over new

    my ipad has gone in lost mode by mistake and now i have it and i enter the password and i cant enter my ipad how can i enter or restart the ipad and start back over new

    FORCE IPAD INTO RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTunes (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port.
    DO NOT RELEASE BUTTON until you see picture of iTunes and plug
    5. Release Home button.
    ON COMPUTER
    6. iTunes has detected iPad in recovery mode. You must restore this iPad before it can be used with iTunes.
    7. Select "Restore iPad"...
    Note:
    1. Data will be lost if you do not have backup
    2. You must follow step 1 to step 4 VERY CLOSELY.
    3. Repeat the process if necessary.

  • Hi I lost the ICloud password and the mail address for it is freezing by the hostage ( hotmail ) so how can I enter my ICloud Account

    Hi
    I lost the ICloud password and the mail address for it is freezing by the hostage ( hotmail ) so how can I enter my ICloud Account

    Hello Cheif Auditor,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    Apple ID: If you forget your password
    http://support.apple.com/kb/ht5787
    Best of luck,
    Mario

  • How can I create a sub-iTunes account for a teen?

    how can I create a sub-iTunes account for a teen?
    I need to separate our music libraries but still keep it under control from the main account (mine).

    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family

  • How do I enter an event in Calendar and repeat it every 3rd day

    How do I enter an event in Calendar and repeat it every 3rd day

    Hello PatrickMaryAnn,
    Thanks for the question, and welcome to Apple Support Communities.
    When editing or creating an event, choose Repeat > Custom… - then choose "Daily" and enter Every 3 days.
    Calendar: Update or delete an event
    http://support.apple.com/kb/PH11509
    Thanks,
    Matt M.

Maybe you are looking for

  • Goods Receipt for Purchase Order Using BAPI 'BAPI_GOODSMVT_CREATE'

    MB01->....->Adopt+details->........... How to fill the table GOODSMVT_ITEM(TALBE of BAPI_GOODSMVT_CREATE'), and final document created  like following: Item Quantity          EUn Material           Plnt  SLoc PO         Item  S DCI                   

  • How to make fields not editable in screen

    Hi gurus, I have a table and i need to make some fields not editable depending on the values of other fields of the table . Example : my table have these fields : begin_date, name. If the begin_date < sy-datum  -->  then the field  ' name' should not

  • How to catch failed rows from excel export data conversion

    I am pulling data from SQL Server and exporting to Excel file.  Using SSIS 2008, sending to Excel 2003.  The process is working fine, and I want to grab any data conversion failures, specifically I want to grab any data that fails or is to be truncat

  • How to solve the plot if shown twice than original data

    Dear sir, I am kunvar yadav, i am using Labview software. Here i going to plot multi plot in single plot. but the problem is it that i am applying the data of 18 days, but in output result shows data of 36 days. Here i have attache original file data

  • Work flow for FI

    Hi, what are the FI-Workflows , and  what are the configaration steps we have to follow for FI-Workflows. Regards, Balu.L