1

I am writing a new script that creates aliases based on the results of an ls query. The script itself is simple enough, however what is hanging me up is the alias call. I cannot figure out how to reference the variable that I've generated in another string when I call the alias command:

for f in `ls -1 -O dir /dev/fs/`
do
  fl=`echo $f | tr '[:upper:]' '[:lower:]'`
  alias "$fl"_drive='cd /dev/fs/$f'
done

It's that reference to the $f variable in the alias call that's throwing me off. Can anyone shed some light on the proper syntax for this? Thanks in advance.

2 Answers 2

3

I guess you properly want $f to point to the file you currently loop over.

The shell doesn't expand anything inside single quotes ('), so your alias contains a literal $f. Use double quotes instead.

alias "$fl"_drive="cd /dev/fs/$f"
Sign up to request clarification or add additional context in comments.

Comments

2

Try:

alias "${fl}_drive"="cd /dev/fs/$f"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.