LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-11-2017, 10:13 PM   #1
bubai70
LQ Newbie
 
Registered: Aug 2012
Posts: 15

Rep: Reputation: Disabled
assigning value with read command vs assigning value with = sign


Hi
past few days I have been working with linux script but I stuck while I read assign value chapter. Kindly explain the difference between all 3 below:

1) var1="this is a variable" [working]

2) var2=this is a variable [not working]

3) read var1 <= enter [working]
what ever you can type here without quotes it will will work
Attached Thumbnails
Click image for larger version

Name:	2017-12-12_09h00_25.jpg
Views:	14
Size:	78.2 KB
ID:	26522  
 
Old 12-11-2017, 10:47 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,784

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Quote:
Originally Posted by bubai70 View Post
Hi
past few days I have been working with linux script but I stuck while I read assign value chapter. Kindly explain the difference between all 3 below:

1) var1="this is a variable" [working]

2) var2=this is a variable [not working]

3) read var1 <= enter [working]
what ever you can type here without quotes it will will work
You have to consider what is being parsed as a command line.

Case #2 is parsed as, "Invoke a command named 'is' with arguments 'a' and 'variable' and with 'var2=this' in the environment."

In case #3, the entire command line is "read var1". What you type in the next line is just text input to the "read" command, which parses its input according to its own rules, which are not the same as command line parsing (about all it shares with command line parsing is word splitting and backslash escapes).

Last edited by rknichols; 12-11-2017 at 10:49 PM.
 
  


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
[SOLVED] problem assigning custom command for an application daudiam Linux - Newbie 2 07-02-2011 08:44 AM
Assigning color in shell, with ls command & HP-UX? juju Other *NIX 14 03-28-2011 01:54 PM
[SOLVED] Assigning Output of a Command to an Array in Perl devUnix Programming 10 11-27-2010 05:43 PM
assigning timestamp of one file to another using touch command Fond_of_Opensource Linux - Newbie 2 11-07-2006 11:17 PM
Assigning the output of one command to a variable (shell) guru_stew Programming 5 08-03-2003 06:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:44 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