From: Dave on 2 Dec 2009 21:16 The output of a command is this /opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1 how can I strip off the path, and so just get the 'libgcc_s.so.1' ? I guess I need to strip from the first character, to the last '/', but are not sure how to do this. Dave -- I respectfully request that this message is not archived by companies as unscrupulous as 'Experts Exchange' . In case you are unaware, 'Experts Exchange' take questions posted on the web and try to find idiots stupid enough to pay for the answers, which were posted freely by others. They are leeches.
From: Bit Twister on 2 Dec 2009 21:44 On Thu, 03 Dec 2009 02:16:28 +0000, Dave wrote: > The output of a command is this > > /opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1 > > how can I strip off the path, and so just get the 'libgcc_s.so.1' ? basename /opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1
From: Ed Morton on 2 Dec 2009 21:55 Dave wrote: > The output of a command is this > > /opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1 > > how can I strip off the path, and so just get the 'libgcc_s.so.1' ? > > I guess I need to strip from the first character, to the last '/', but > are not sure how to do this. > > Dave $ var="/opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1" $ echo "$var" /opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1 $ echo "${var##*/}" libgcc_s.so.1 Ed.
From: Rakesh Sharma on 3 Dec 2009 03:02 On Dec 3, 7:16 am, Dave <f...(a)coo.com> wrote: > The output of a command is this > > /opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1 > > how can I strip off the path, and so just get the 'libgcc_s.so.1' ? > > I guess I need to strip from the first character, to the last '/', but are not > sure how to do this. > Apart from the command 'basename' which is tailor-made for this task, you could do this too: out='/opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1' savIFS=$IFS IFS='/' set -f set x $out; shift for var do : done IFS=$savIFS printf '%s\n' "$var" ## or you could simply do: printf '%s\n' "$out" | sed -e 's|.*/||' --Rakesh
From: Chris F.A. Johnson on 3 Dec 2009 03:30 On 2009-12-03, Rakesh Sharma wrote: > On Dec 3, 7:16?am, Dave <f...(a)coo.com> wrote: >> The output of a command is this >> >> /opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1 >> >> how can I strip off the path, and so just get the 'libgcc_s.so.1' ? >> >> I guess I need to strip from the first character, to the last '/', but are not >> sure how to do this. >> > > Apart from the command 'basename' which is tailor-made for this task, As is POSIX parameter expansion. > you could do this too: > > out='/opt/kirkby/gcc-4.4.2/lib/libgcc_s.so.1' > savIFS=$IFS IFS='/' > set -f > set x $out; shift > for var > do > : > done > IFS=$savIFS > printf '%s\n' "$var" > > ## or you could simply do: > printf '%s\n' "$out" | sed -e 's|.*/||' -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Nail mailrc save/write 'no active mailbox' Next: ls with creation time |