LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-14-2007, 03:18 AM   #1
frankie_DJ
Member
 
Registered: Sep 2004
Location: NorCal
Distribution: slackware 10.1 comfy, Solaris10 learning
Posts: 232

Rep: Reputation: 32
bash: strange problem with pathname expansion


OK, here is my problem. It seems simple, but I can't seem to figure out what is wrong.

I have a directory with the name

1.98gcm-3

and my script is supposed to operate in its parent directory. One of the variables is called digit, and I inputed it's value to be 1. So

$digit=1

But when I want to change directory in my script in the following way:

cd $digit*/radialdata

it gives me an error: No such file or directory. Shouldn't it expand $digit* to 1.98gcm-3 ? It expands it to

1*

The only directory that starts with 1 is 1.98gcm-3. I am really confused.

Thanks for your help.

Last edited by frankie_DJ; 01-14-2007 at 03:20 AM.
 
Old 01-14-2007, 05:37 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Did you fill digit or $digit with 1?

It should be digit. The following works:

digit=1
cd $digit*/radialdata


Hope this helps.
 
Old 01-14-2007, 07:16 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
yeah, assigment in the shell doesn't use the $ on the variable name, i.e.
Code:
myvar=1    # like this
$myvar=1   # not like this
In the shell you only use the $ to say "give me the value which is currently assigned to this variable", e.g.
Code:
echo "the value is $myvar"   # like this
echo "the value is myvar"    # not like this
Perl always uses the $, C and C++ don't use a $ at all, neither do awk or python. TCL does use $, but like the shell - only to take the value. Assembler doesn't know what a variable is (although there are pre-processors which pretend to).

I think language designers have the idea that confusion is an important part of writing a new language. Don't get me started on "else if" variants. Egad!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash variables expansion olaola Linux - Newbie 4 10-16-2006 11:45 AM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 11:31 AM
Bash Script Expansion Problem meadensi Linux - Newbie 1 03-04-2005 05:17 PM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM
Scripting help -- pathname expansion player_2 Programming 3 08-25-2003 05:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration