Variables not working

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variables not working
# 1  
Old 09-11-2013
Linux Variables not working

I have a (basic I guess) problem with bash scripting.
In the command line, this piece of code returns nothing (a blank line), and if I'm not worng it should return 3.

set VAR = "3"
echo $VAR

if I do this (also in command line), a zero is returned:
set VAR = 3
printf "%d" "$VAR"

I also tried this code, with the same result, nothing is shown

set PID = 3;
echo $PID;

I hope someone can help me, this is cracking my nut.
Thankx in advanced.

Last edited by Scott; 09-11-2013 at 04:01 PM.. Reason: Code tags, not Icode tags
# 2  
Old 09-11-2013
set PID = 3

is not Bash syntax. It's CSH syntax:
$ csh
% set PID = 3
% echo $PID


is Bash syntax.

You can use:
set PID=3

but it's not necessary to use set.
# 3  
Old 09-11-2013
I also tryied that: VAR = "3"; echo $VAR

with this result: bash: VAR: command not found

thankx eitherway
# 4  
Old 09-11-2013
There should be no spaces either side of =.
This User Gave Thanks to Scott For This Post:
# 5  
Old 09-11-2013
that was it.

thank you very much for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SHELL: UNIX : Ls regular expression not working when used with variables

If i do below command in unix prompt which static values (ie 27..97), it is working fine and gives desired output >ls -d $WORKDIR/batch/somefilename_{27..97}.* 2>/dev/null somefilename_27.sometxt somefilename_28.sometxt somefilename_29.sometxt .. somefilename_97.sometxt But if i want... (2 Replies)
Discussion started by: haiderali
2 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

Working with lines or variables that have spaces or special characters

Example: while read line do stat -c %G $line done < somefile.txtThe problem is that inside somefile.txt lines can have any symbol allowed as file name, like (). Even with spaces, it splits the words. somefile.txt:dira/my first jump.avi dirb/surf video (1080p).mkv (2 Replies)
Discussion started by: Tribe
2 Replies

4. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

5. Shell Programming and Scripting

echo two variables like the paste command is not working

Dear all, I have two files like this file1 A B C D E F file2 1,2 3,4 5,6 I want this output output_expected A B 1,2 C D 3,4 E F 5,6 (3 Replies)
Discussion started by: valente
3 Replies

6. Shell Programming and Scripting

[Solved] Working with date (add minutes using variables)

Dear all, today I'm scratching my head with a simple (I believe) issue. Working with date is quite simple, so if I Need to add some seconds to current time, I'll use: date --date='+30 seconds' +"%Y-%m-%d %H:%M:%S"But, how to pass the value to add from a variable? I tried the following without... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

7. Shell Programming and Scripting

using variables in perl not working

sdcprd@dotstoas110:$ echo $F2 1327332411 this works ---------- sdcprd@dotstoas110:$ perl -MPOSIX -le 'print strftime ("%m%d%y",localtime (1327332411))' 012312 <<<< correct date this doesnt ----------- sdcprd@dotstoas110:$ perl -MPOSIX -le 'print strftime ("%m%d%y",localtime... (10 Replies)
Discussion started by: aliyesami
10 Replies

8. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

9. UNIX for Dummies Questions & Answers

Working with Script variables; seems like this should work...

The following seems quite basic but does not seem to work. Anybody know why? $ g=1 $ echo $g 1 $ echo abc$g abc1 $ abc$g=hello ksh: abc1=hello: not found $ echo $abc1 ksh: abc1: parameter not set It works when I specify the full variable name $ abc1=hello $ echo $abc1 hello ... (2 Replies)
Discussion started by: Chong Lee
2 Replies

10. AIX

Setting Variables not working

Hi all, I am trying to set up some variables in a shell script. The variables contain values of various paths needed to run a java module. The problem is the variables dont seem to be setting at all. here is what i am trying to do : JAR_HOME=/home/was5/bdcms/scheduledjobs/lib export... (1 Reply)
Discussion started by: rpandey
1 Replies
Login or Register to Ask a Question