echo prints nothing-shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo prints nothing-shell script
# 1  
Old 09-01-2010
echo prints nothing-shell script

could anyone tell me why when i execute the following script, echo returns blank

set k = 1
echo $k
# 2  
Old 09-01-2010
Without knowing what Shell you have, this is difficult!

In "csh" your statement works. Therefore we assume it is not "csh".

In Bourne-type shells (sh, ksh, bash etc.) it should be a syntax error. The "set" command is for setting shell parameters. The "typeset" command may be what you meant but for this simple example we just assign the variable. Note that there are no spaces either side of the equals sign.

Code:
#!/bin/sh
k=1
echo $k

1

Code:
#!/bin/sh
typeset k=1
echo $k

1

This User Gave Thanks to methyl For This Post:
# 3  
Old 09-01-2010
echo prints nothing

Code:
#!/bin/sh
k=1
echo $k

1

Code:
#!/bin/sh
typeset k=1
echo $k

I tried them but I receive error:
split.sh: line 4: typeset: `=': not a valid identifier
split.sh: line 4: typeset: `1': not a valid identifier

1

[/QUOTE]
my shell is
Code:
/bin/bash

# 4  
Old 09-01-2010
If you have bash, then the shebang line will probably be:

Code:
#!/bin/bash

Apart from that, there is much variation in Shell syntax. How you set a variable will depend on how you want to use it. If you need to declare a variable with a non-default use, see the "typeset" section in your "bash" manual. Most of the time it is not necessary to use "typeset".
This User Gave Thanks to methyl For This Post:
# 5  
Old 09-01-2010
I found the problem, I was giving some space here:
Code:
typeset k = 1

which is illegal, now that i correct it, it works fine.
Code:
typeset k=1



---------- Post updated at 09:45 PM ---------- Previous update was at 09:44 PM ----------

I found the problem, I was giving some space here:
Code:
typeset k = 1

which is illegal, now that i correct it, it works fine.
Code:
typeset k=1

# 6  
Old 09-01-2010
Spaces are indeed very important in "bash" Shell syntax.
# 7  
Old 09-01-2010
There's plenty of "magic" spaces in most any shell, really.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Php script prints values but not seen in browser

greetings, i'm a php and html novice and i figured i'd learn by diving in. i've written a php script that i've placed in the /var/www/html directory. it's supposed to give some relative info about the system when you point a browser at it. if i run the script using "php -q index.php" all the... (3 Replies)
Discussion started by: crimso
3 Replies

2. Shell Programming and Scripting

How to echo output of a UNIX command (like ls -l ) using shell script.?

How do i echo the output of a unix command using shell script??? Like: echo /etc/ ls -l (2 Replies)
Discussion started by: sunny2802
2 Replies

3. Shell Programming and Scripting

Script which telnets to a device, runs commands and prints output to a file

I am connecting to a device using telnet, I want my script to perform certain commands : ie- show device , show inventory..etc and write the output it sees from the terminal to a file. this is what I have got : #!/usr/bin/expect -- set running 1 spawn telnet <ip address> expect ... (1 Reply)
Discussion started by: samantha123
1 Replies

4. Shell Programming and Scripting

Script to compare 2 files and prints difference as output sidebyside

Hi All, Am trying script to compare 2 files and print the difference found from old file to new file on line by line basis on side by side display. Basically line by line comparision and files may contain blank line as well I know we have compare/diff commands but i don't how to make... (10 Replies)
Discussion started by: Optimus81
10 Replies

5. Shell Programming and Scripting

Shell script that check the argument passed to it and prints error if test condition is not met

I want to make a script that check for the argument passed to it and generates an error in case any character/string argument passed to it. I am using below code, but its not working. can anyone help. #!/bin/bash if ]; then echo 'An integer argument is passed to the script hence... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

6. Shell Programming and Scripting

Shell Script if $2 is greater than 10 then echo $1

Hi, I have a file output.txt 3258 14 32647 10 32649 10 32650 10 32651 10 32652 10 32653 10 32654 10 32655 10 32656 10 32515 09 32478 08 32555 08 35888 08 (4 Replies)
Discussion started by: amit_spl
4 Replies

7. Emergency UNIX and Linux Support

Script issue - Prints pages with jibberish...

Hi all, I have a script from a programmer, for which I need to analyze a problem. The script gathers audit info and prints out the results. Two different departments use it, on two different printers. In the script department the there are no issues. In the other department the same script... (10 Replies)
Discussion started by: zixzix01
10 Replies

8. Shell Programming and Scripting

Script that prints 2 messages to a screen session

Im trying to make a script that prints 2 messages to a screen session, one after the other. screen -x session44 -X stuff "`printf "Test 1\r"`" This works fine, but adding a second lien with a different message yields no results. Changed Subject: Please Follow Forum Rules Regarding... (1 Reply)
Discussion started by: kylecn
1 Replies

9. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

10. UNIX for Advanced & Expert Users

run a shell script with echo

I need to schedule a shell script that runs at the command prompt to run with crontab. When I run this at the command prompt as follows it works: echo /usr/test/script.sh date1 date2 y | at 20:00 But if I will pass these argument (date1, date2, Y) with in a shell script (say scr1.sh) and... (7 Replies)
Discussion started by: keerthi
7 Replies
Login or Register to Ask a Question