LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 04-21-2004, 12:15 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Bash script


1) What is the ${#HOSTNAME} means ?
2) I think hostname "$HOSTNAME" means set the variable
hostname to whatever value is in HOSTNAME.
3) What is the difference between
hostname "$HOSTNAME" and hostname $HOSTNAME ?

==========================

if [${#HOSTNAME} -ne 0]; then
hostname "$HOSTNAME"
fi
 
Old 04-21-2004, 03:02 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
1) I have never seen a variable written with a hash (#) in front, so all I can assume is that the variables name is "#HOSTNAME" but I am probably totally wrong on this one...

2) Actually, this is running the "hostname" program with the value of "$HOSTNAME" as an argument. Variable assignment uses the equals sign ie: hostname=$HOSTNAME

3) Quoting the variable preserves whitespace when referencing it. ie:
Code:
hello="A B  C   D"
echo $hello  
$ A B C D
echo "$hello" 
$ A B  C   D
If you haven't already, checkout the Advanced BASH Scripting Guide, it has everything you want to know about BASH scripting and lots of example code.
http://www.tldp.org/LDP/abs/html/index.html

Last edited by bulliver; 04-21-2004 at 03:07 PM.
 
Old 04-21-2004, 04:20 PM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

Thank you bulliver for your help.
 
Old 04-21-2004, 06:03 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Re: Bash script

Quote:
Originally posted by Linh
1) What is the ${#HOSTNAME} means ?
It expands to the number of characters in the variable $HOSTNAME.
In other words: the length of $HOSTNAME.
For example if HOSTNAME is "Linh", then "echo $(#HOSTNAME)" prints "4".
If it is "Hko", then it prints "3".
 
Old 04-21-2004, 06:19 PM   #5
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

Thank you HKo for your help
 
  


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 script moodupani Programming 3 08-30-2005 08:31 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM
bash script brian0918 Programming 7 06-12-2003 07:06 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 06:34 AM


All times are GMT -5. The time now is 02:02 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration