Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Nov 2007 11:10:29 -0800 (PST)
From:      White Hat <pigskin_referee@yahoo.com>
To:        FreeBSD Users Questions <freebsd-questions@freebsd.org>
Subject:   Storing variable in Bash
Message-ID:  <542256.58741.qm@web34409.mail.mud.yahoo.com>

next in thread | raw e-mail | index | archive | help

I am attempting to write a script that will work on files stored in an array. The function is supposed to strip the files extension and then store the name of the file as a variable. This is what I have so far.
 
#!/usr/local/bin/bash

declare -a fname
declare -i count
declare -i limit

fname=( `ls *.sh | tr '\n' ' '` )
count=${#fname[*]}
limit=0

while [ ${limit} -lt ${count} ]; do
echo ${fname[$limit]} | sed -e ``/.sh/s///''
# do something here
limit=$((limit+1))
done
 
What I want to do is store the file in a variable. I have tried this:
 
F_Name=echo ${fname[$limit]} | sed -e ``/.sh/s///''
 
As well as:
 
F_Name=( `echo ${fname[$limit]} | sed -e ``/.sh/s///''` )
 
along with several different variants of it, but without success. I continually receive an error message. Due to a particular situation, I cannot use 'basename' to accomplish this task.
 
Is there anyway that this can be done?
 
Thanks!
-- 
White Hat 
pigskin_referee@yahoo.com


      ____________________________________________________________________________________
Get easy, one-click access to your favorites. 
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?542256.58741.qm>