Function works, trigger causes syntax error, whats my fault??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Function works, trigger causes syntax error, whats my fault??
# 1  
Old 08-14-2014
Function works, trigger causes syntax error, whats my fault??

Needing a hint. Creating that function called Meter my simple script works well. What I want now is to start the last four commented lines to include or trigger a reaction, if there are more than n lines in that .txt-file it shall display that message for example. But the interpreter says there is a syntax-error. Any hints? Thanks in advance!

Code:
#!/bin/bash
# name of the script is line3.sh
set -e
set -u
echo $0 

Meter ()
    {

Zet=$(wc -l /home/$USER/Desktop/14tilt.txt)
Ted=$(wc -c /home/$USER/Desktop/14tilt.txt)
    
}

Meter

echo "lines"    $Zet | cut -d '/' -f1 &&
echo "bytes"   $Ted | cut -d '/' -f1;

#if [ $Zet -gt 400 ]
# then echo "did it"
# else echo "not yet"
#fi;

exit 0;

But I am sure that this specific textfile contains more than 400 lines. So what can I do?

Last edited by 1in10; 08-14-2014 at 10:24 PM.. Reason: better reading
# 2  
Old 08-15-2014
What output are you getting when you run your shell script?
What output do you get running the command:
Code:
wc /home/$USER/Desktop/14tilt.txt

when you run it in your shell interactively?

Have you tried running your shell script like this?:
Code:
bash -xv line3.sh

Does the trace it provides give you any indication of what is wrong?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-15-2014
Try:
Code:
Zet=$(wc -l < /home/$USER/Desktop/14tilt.txt)
Ted=$(wc -c < /home/$USER/Desktop/14tilt.txt)

Then you should not need the cut commands either...
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 4  
Old 08-15-2014
Best solution was "<" for directing the input and making obsolete by this the cut-statement. Before doing so the interpreter was mourning about a missing definition of the /home-folder. BTW thanks to Don Cragun as well, for the hint with "bash -xv name-of-the-script.sh", that is reeeeaallllyy good. It told me the steps after the correction.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash function using variable in it syntax error

The below bash function uses multiple variables CODING, SAMPLE, SURVEY, andvariant in it. The user selects the cap function and details are displayed on the screen using the $SURVEY variable, the directory is changed to $SAMPLE and the samples.txt is opened so the user can select the sample to... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Python - Function print vs return - whats wrong

All, I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this #!/usr/bin/python def div4and6(s,e): for i in range(s,e+1): if... (5 Replies)
Discussion started by: oky
5 Replies

3. Shell Programming and Scripting

Syntax Error while using CMP function

Hi All, I am getting a syntax error message while trying to compare 2 files using the compare function (LINUX) command substitution: line 79: syntax error near unexpected token `(' command substitution: line 79: `cmp -s <(tr , \n < $COMMON_TMP/nt_per_gs.done | sort) <(tr , \n <... (5 Replies)
Discussion started by: dsfreddie
5 Replies

4. Shell Programming and Scripting

Syntax error piping to bc on command line - works when assigned to var

I have a script which outputs some timing data a line at a time. There are approx. 10 lines echoed, each line looks something like this: 0.741 http://checkip.dyndns.org 94.170.119.226Since I needed to add all the values in the first column, I piped the output to grep, matching and printing the... (7 Replies)
Discussion started by: gencon
7 Replies

5. Shell Programming and Scripting

whats the function of brackets here ?

Hello, as the title reads, in a control flow like "if" what's the function of brackets ? if condition then ... if ] then ... Since I saw people using them I wonder whether they are just inserts for code clearness or for the reliability ? thanks for your help Regards (9 Replies)
Discussion started by: Oddant
9 Replies

6. Shell Programming and Scripting

Whats wrong in the Function ?

Need your assistance, to find the bug in the function. Function usage erroring out even after passing parameters. usage() { if || ; then echo "************************************************************" echo " CHECK USAGE FOR CORRECT PARAMETERS ... (26 Replies)
Discussion started by: raghunsi
26 Replies

7. Programming

segmentation fault while returning from function.

I am working on the application in which I have to fetch values from the database and paste in url and send it to portal. table=get_result("SELECT serialno,cas,Mode,FLC,TLC,location,CompName,CompCode,FG,FC,DispNo,TruckNo,LWbill,RRGPN,INVNO,DCN,RQTY,DQTY,SQTY,DDATE,RDATE,SDATE,TTIME FROM... (1 Reply)
Discussion started by: er.rohan88
1 Replies

8. Solaris

Whats the syntax for 'cut' in following?

Guys I am trying to get all physical plus logical interfaces on a host to pass them to a 'for' loop. 'ifconfig -a' gives me all interfaces like following...i need to cut last ':' from this list.What 'cut' syntax i need to use? bash-2.05$ ifconfig -a|awk '{print $1}'|sort|uniq|egrep -v... (13 Replies)
Discussion started by: ak835
13 Replies

9. Shell Programming and Scripting

Whats wrong with the syntax

Whats wrong with below logic or syntax???? (4 Replies)
Discussion started by: dsravan
4 Replies

10. Shell Programming and Scripting

Whats wrong with my function?? <newbie>

First of all im using Bash, on a Debian-based machine. I tried to write a function that if the ls program found listed more than 25 lines I would automaticly use "ls | less". Its on another computer but if I recall it looked something like this... Note: some code may look strange because im on... (4 Replies)
Discussion started by: riwa
4 Replies
Login or Register to Ask a Question