How to print last character of hostname and assign to a variable ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print last character of hostname and assign to a variable ?
# 8  
Old 04-17-2019
Code:
echo ${HOSTNAME: -1}

These 2 Users Gave Thanks to nezabudka For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies

2. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

Hello All, Hope you're doing well ! I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted. header_date_14=$(m_dump... (8 Replies)
Discussion started by: ektubbe
8 Replies

3. Shell Programming and Scripting

Remove a character and assign result to a variable

I am reading lines from a file that contain a number sign (#) before a three or four digit number: #1043 #677 I can remove the '#' and get just the number. However, I then want to assign that number to a variable and use it as part of a path further on in my program: /mydir/10/1043 for... (5 Replies)
Discussion started by: KathyB148
5 Replies

4. Shell Programming and Scripting

Assign a variable the nth character of a string.

I see a millioin ways to do this with echo, but what I wan to do is assign a variable the "nth" character of an incoming parameter to a ksh script. $1 will be "pia" I need to assign the first character to stmttype. (10 Replies)
Discussion started by: klarue
10 Replies

5. Programming

Unable to assign zero to unsigned character array

Hi, I am unable to assign value zero to my variable which is defined as unsigned char. typedef struct ABCD { unsigned char abc; unsigned char def; unsigned char ghi; } ABCD; typedef ABCD *PABCD; In my Por*C code, i assign the values using memcpy like below ... (3 Replies)
Discussion started by: gthangav
3 Replies

6. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

7. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

8. Shell Programming and Scripting

print ip to hostname with array

Hi Anyone can help me??i writing a perl using array to translate ip address to the hostname my script are below.this line print "$myhost{$ipaddr}\n"; blank :mad:hostname dint come out:mad::mad: #!/usr/local/bin/perl @ipaddr=("192.1.168.2","172.25.1.13","129.1.2.5"); %myhost = { 192.1.168.2... (4 Replies)
Discussion started by: netxus
4 Replies

9. Shell Programming and Scripting

Print the first four characters of hostname

Hey, I'm trying to print the first four characters of the hostname of a computer. I can get it from using: hostname -s | sed 's/...........$//'" but this is when I know how many characters are in the computer name. I dont understand why some like: hostname -s | sed '/..../p' wont... (7 Replies)
Discussion started by: yxian
7 Replies

10. Shell Programming and Scripting

read and assign each character from the string to a variable

How... can I read input by a user character by cahracter. And assign each character from the string to a variable? Any help would be greatly appreciated! Thank you! (1 Reply)
Discussion started by: Tek-E
1 Replies
Login or Register to Ask a Question
ECHO(3) 								 1								   ECHO(3)

echo - Output one or more strings

SYNOPSIS
void echo (string $arg1, [string $...]) DESCRIPTION
Outputs all parameters. echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses. echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syn- tax only works with the short_open_tag configuration setting enabled. I have <?=$foo?> foo. PARAMETERS
o $arg1 - The parameter to output. o $... - RETURN VALUES
No value is returned. EXAMPLES
Example #1 echo examples <?php echo "Hello World"; echo "This spans multiple lines. The newlines will be output as well"; echo "This spans multiple lines. The newlines will be output as well."; echo "Escaping characters is done "Like this"."; // You can use variables inside of an echo statement $foo = "foobar"; $bar = "barbaz"; echo "foo is $foo"; // foo is foobar // You can also use arrays $baz = array("value" => "foo"); echo "this is {$baz['value']} !"; // this is foo ! // Using single quotes will print the variable name, not the value echo 'foo is $foo'; // foo is $foo // If you are not using any other characters, you can just echo variables echo $foo; // foobar echo $foo,$bar; // foobarbarbaz // Some people prefer passing multiple parameters to echo over concatenation. echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10); echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . " "; echo <<<END This uses the "here document" syntax to output multiple lines with $variable interpolation. Note that the here document terminator must appear on a line with just a semicolon. no extra whitespace! END; // Because echo does not behave like a function, the following code is invalid. ($some_var) ? echo 'true' : echo 'false'; // However, the following examples will work: ($some_var) ? print 'true' : print 'false'; // print is also a construct, but // it behaves like a function, so // it may be used in this context. echo $some_var ? 'true': 'false'; // changing the statement around ?> NOTES
Note Because this is a language construct and not a function, it cannot be called using variable functions. SEE ALSO
print(3), printf(3), flush(3), Heredoc syntax. PHP Documentation Group ECHO(3)