Question about syntax error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about syntax error
# 1  
Old 04-04-2012
Question about syntax error

first of all.. sorry about all the question bombing.. im bored atm so im currently playing around with sh scripting hehe

Code:
s = `expr ls -s Documents | grep Music | awk '{ print $1 }' `    
t = `expr $t + $s`

it give syntax error
s not found
t not found lol...
any idea why?

Last edited by Scrutinizer; 04-04-2012 at 02:09 PM.. Reason: Code tags
# 2  
Old 04-04-2012
Remove the spaces in the assignments:
Code:
s=something

# 3  
Old 04-04-2012
u mean?

Code:
s=`expr ls -s Documents | grep Music | awk '{print $1}' `

doesnt work too.. i even tried {Documents} {Music}
none work

---------- Post updated at 12:04 PM ---------- Previous update was at 12:03 PM ----------

maybe expr doesnt work with that? cause i tried

Code:
ls -s Documents | grep Music | awk '{print $1}'

it does give the result... just the s doesnt record it
# 4  
Old 04-04-2012
You don't need expr for that, just backticks or $(...).
Code:
s=$(ls -s Documents | grep Music | awk '{print $1}')

# 5  
Old 04-04-2012
bracket doesn't work, maybe cause it's sh? but backticks work
not on this (below)
i though this is suppose to work? judging from http://cis.stvincent.edu/html/tutorials/unix/bshellref
i'm learning about sh from there

t=`expr $t + $s`
it gives me syntax error

Last edited by Nick1097; 04-04-2012 at 02:38 PM..
# 6  
Old 04-04-2012
Hello,

Per our forum rules, all users must write in English, use semi-formal or formal English language and style, and correct spelling errors.

The reason for this is that most software and operating systems are written in English and these are software related technical forums.

In addition, nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, you need to spell correctly!

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your language, check your spelling and correct your spelling errors. You might receive a forum infraction if you don't pay attention to this.

Also, do not write in cyberpunk or abbreviated chat style under any circumstances and do not use profanity. This is not a chat room, it is a formal knowledge base to serve you and everyone, of all ages and cultural backgrounds.

Thanks!

The UNIX and Linux Forums
# 7  
Old 04-04-2012
Quote:
Originally Posted by Nick1097
bracket doesnt work... maybe cause it's sh... but backtick work
not on this tho... i tho this is suppose to work? judging from http://cis.stvincent.edu/html/tutorials/unix/bshellref
learning bout sh from there hehe

t=`expr $t + $s`funny.. and it gives me syntax error lol
That is Bourne Shell, hardly any system uses that nowadays. On most systems /bin/sh stands for a POSIX shell, in which $( ) does work. A modern day exception is Solaris, where /bin/sh is in fact still a Bourne Shell, but it also has /usr/xpg4/bin/sh which is a POSIX compliant shell..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question regarding quotation syntax

Hey guys, my first post on UNIX Forums(much overdue IMO)! I've got this bit of code that doesn't seem to be working correctly for an Android app I'm working on: "screen -S gmod1 -p 0 -X stuff " & "" & command.text & "`echo -ne '\015'`""" Basically it types command.text(variable determined... (4 Replies)
Discussion started by: stingwraith
4 Replies

2. Shell Programming and Scripting

A Perl Syntax Question.

Greetings! Here's what I believe is a "simple one" for the community tonight ;) What I'm trying to do is assign a "true/false" value to a variable depending upon whether a named process (some-process) exists; and then test for this value in the succeeding logic. I banged my head against the... (2 Replies)
Discussion started by: LinQ
2 Replies

3. Programming

Perl syntax question

Hallo everybody, I have a following problem - I'm doing a map funciont to fill in a HTML table and I want to use some radiobutton groups. Unfortunatelly, they are grouped by names, so I have to add some "counter" that will divide one row from another, and I'm using CGI.pm for generating the... (3 Replies)
Discussion started by: duskos
3 Replies

4. Shell Programming and Scripting

tar -C syntax question

I am writing a perl script to tar multiple files (in unix) from a given directory to a given output directory. I do NOT want the file path included in the tar, so I've flagged the -C option. Example: tar -cvf tar/1.tar -C htmp/source/ 1-1-1.xml However, I need to do this for a number of target... (3 Replies)
Discussion started by: michanjohns
3 Replies

5. UNIX for Advanced & Expert Users

SNMP syntax question

Hello, I need to create an snmp.comf file that defines 2 IPs to the same community string. Do I need to have 2 community strings with the same name and diff't IPs? Or should I have 1 string and list the IPs? (comma seperated?) Example: rocommunity EC_8000_RO arguments EC_8000_RO... (2 Replies)
Discussion started by: felbvts
2 Replies

6. Programming

Newbie Question.. -> error: syntax error before ';' token

Hello, the following is generating a error at the line "tmprintf(&tmBundle, _TMC("{0}"),Prompt);"... a bit lost as I am diving into this debug... Thank you in advance... int H_YesNo(TMCHAR *Prompt, int DefVal) { TMCHAR YesNo = '\0'; tmprintf(&tmBundle, _TMC("{0}"),Prompt); while... (3 Replies)
Discussion started by: reelflytime
3 Replies

7. Shell Programming and Scripting

awk syntax question

Hi I use awk command to delete the first blanc line of a file: awk '/^$/ && !f{f=1;next}1' infile > outfile can somebody please explain me what the last "1'" in !f{f=1;next}1' stands for... Thansk a lot -A (3 Replies)
Discussion started by: aoussenko
3 Replies

8. UNIX for Dummies Questions & Answers

Piping syntax question

There are are lots of examples of piping output FROM the 'ls' command TO another command, but how does one pipe output TO the 'ls -l' command? For example, use 'which' to find a file, then use 'ls -l' to view the permissions, groups, etc. in a single step: which <filename> | ls -l returns... (4 Replies)
Discussion started by: johne1
4 Replies

9. UNIX for Dummies Questions & Answers

AWK syntax question

Hi, Have to check file names in some given directory. SO, What is the right syntax here: *$3*=="'$object_list'" - just wanted to check if $3 is in the object_list. And also, Do I need so many quotes around? (5 Replies)
Discussion started by: Leo_NN
5 Replies

10. Shell Programming and Scripting

awk syntax question

Hi there could someone explain what is happening in the following function/statement for me, im just a little confused code = 'BEGIN{FS=","} { printf ("%-11s,%s%s%s,%07.2f,%14s,%-3s\n",$1,substr($2,9,2),substr($2,6,2),substr($ 2,3,2),$9,$10,$12) } this function is called later in the... (2 Replies)
Discussion started by: hcclnoodles
2 Replies
Login or Register to Ask a Question