Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: how to handle strings with spaces

  1. #11
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: how to handle strings with spaces

    Yeah, I was using sh not bash. I've got it working now so I'll stick with it, what I've got works with both bash and sh. I guess that line means something.
    why would you want to use sh for your own userspace scripts? Do you have a computer from the 20th century that shaving off that 100k of RAM matters? Bash offers tons of nifty stuff that is not accessible in sh (dash)
    You are gimping yourself for no reason. If you have cool features within your arms reach, use them, don't reinvent the wheel with hackish workarounds for the sake of it. These features were in fact implemented to alleviate many of such basic problems like this one.

    bash <( cmd ) that means 'capture the cmd output and make a fake file of it' is incredibly powerful, it works everywhere you would use files as input. some_command file? have some_command <( cmd ) instead. You don't pollute your hdd with temporary dump files and can cut to the chase.
    Last edited by Vaphell; March 25th, 2013 at 11:49 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  2. #12
    Join Date
    Sep 2008
    Location
    England
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: how to handle strings with spaces

    Quote Originally Posted by schragge View Post
    Quote file names with spaces:
    Code:
    #!/bin/sh
    file='/original/folder/sub folder/file.txt'
    path="${file%/*}"
    newpath="${path#/*/}"
    mkdir -p "$newpath"
    cp "$file" "$newpath"
    Quote Originally Posted by Vaphell View Post
    why would you want to use sh for your own userspace scripts? Do you have a computer from the 20th century that shaving off that 100k of RAM matters? Bash offers tons of nifty stuff that is not accessible in sh (dash)
    You are gimping yourself for no reason. If you have cool features within your arms reach, use them, don't reinvent the wheel with hackish workarounds for the sake of it. These features were in fact implemented to alleviate many of such basic problems like this one.
    I finally got my script working, but yes I'm using work arounds. Like creating text files and replacing spaces with underscore. Ok, I'll make it better, I know it's the best way to learn.

    EDIT: I think I know what I'm doing, so wanted to mark the thread as solved. Can anyone tell me how??
    Last edited by AmbiguousOutlier; March 25th, 2013 at 11:58 PM.

  3. #13
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,657
    Distro
    Ubuntu

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •