From: Dave on
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
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
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
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
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 =====