LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 10-28-2008, 08:13 AM   #1
Jacky Quah
LQ Newbie
 
Registered: May 2005
Posts: 28

Rep: Reputation: 15
Bash Script: form $(< file) ?


Bash Script: form $(< file)
I don't know the filename, the filename is stored in variable (say it $TEST), how can I do that ?

because $(< $TEST); show error...
 
Old 10-28-2008, 09:13 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Works for me. Does the file really exist? What error are you getting?
 
Old 10-28-2008, 09:25 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It works for me, too. Which is the error message? Also to debug your script you can try to run it as
Code:
bash -x script.sh
this will show you a detailed trace of all the executed commands and the related variable substitutions.
 
Old 10-28-2008, 10:38 AM   #4
Jacky Quah
LQ Newbie
 
Registered: May 2005
Posts: 28

Original Poster
Rep: Reputation: 15
Ops sorry, I guess it's the problem is not that..

My bad habit...; with php...
I write something like this...
$T2=$(< $TEST);
lol. doesn't even realise what's wrong...
 
Old 10-28-2008, 12:33 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Jacky Quah View Post
I write something like this...
$T2=$(< $TEST);
lol. doesn't even realise what's wrong...
Ok. I try to interpret in simple words what you're trying to do: you want to assign the content of the file, whose name is stored in the variable TEST, to the variable T2. Right?

The error in the statement above is that you cannot have $T2 to the left hand side of an assignement, but simply T2, that is the name of the variable.

When you write $T2 you mean the value of the variable T2 and the statement above looks like a comparison instead of an assignment. Hope it is clear now!
 
  


Reply



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
How to take value from file (bash script) teguh.purnama Linux - Newbie 3 09-08-2008 07:32 AM
Bash script to remove capitalisation and spaces form a filename scuzzman Programming 11 05-18-2008 12:28 PM
Script to get form data..in bash? jrfly Linux - General 1 06-29-2005 10:04 AM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
I want Linux source code for FAT file system in user readable form not in binary form ramya272 Linux - Newbie 5 02-05-2004 07:54 PM

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

All times are GMT -5. The time now is 10:09 PM.

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