4129 links
740 private links
  • Doo's links
  • Home
  • Login
  • RSS Feed
  • ATOM Feed
  • Tag cloud
  • Picture wall
  • Daily
  • ► Jouer les vidéos
Links per page: 20 50 100
  • thumbnail
    bash - Why does "$i | sed" not work? - Unix & Linux Stack Exchange

    You can substitute the value of $i in to see the exact command you're trying to run:

    app4/ | sed -e "s/^.*(.)$/\1/"

    This doesn't work because app4/ isn't a command. You're trying to pipe app4/ into sed, so you need to use something that outputs app4/:

    echo app4/ | sed -e "s/^.*(.)$/\1/"

    This works, but you don't really need to use sed for this; bash has quite a few string manipulation tools. For example, ${i#} will give you the length of $i, and ${i:j} will give you a substring starting at j, so ${i:$((${i#}-1))} will give you the last character.

    The easiest way to do what you're trying is probably with ${i%/}. This will return $i, but will strip off a / from the end if there is one:

    $ i="app4"; echo ${i%/}
    app4
    $ i="app4/"; echo ${i%/}
    app4

    Thus:

    if [ "${i%/}" = "$i" ]
    then
    echo "file"
    else
    echo "folder"
    fi

    However, if all you really want is to know if $i is a valid directory, you can just use:

    if [ -d "$i" ]

    November 2, 2013 09:58:05 PM GMT+01:00 - permalink -
    QRCode
    - http://unix.stackexchange.com/questions/27334/why-does-i-sed-not-work#27336
    sed hack tool linux bash
Links per page: 20 50 100
Shaarli - The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community - Help/documentation