how do you use brackets ?? in a script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how do you use brackets ?? in a script.
# 1  
Old 09-22-2004
Question how do you use brackets ?? in a script.

Smilie i am pretty much new to scripting and don't want to pick up bad habits so I am trying to get myself to use brackets in my scripts since I plan on using them alot.. !
in this example of a script I wrote I can not figure out where the brackets go can anyone give me some insight into the use of brackets..??

# !/bin/sh
# .clear
TTY=`tty`
function fun { clear; pwd; date; tty; }
echo "enter term:"
read term
if [ "$TTY" == "/dev/pts/$term" ]
then
fun
echo "experimental terminal" > /dev/pts/$term
elif [ "$term" == "z" ]
then
fun
ls -ali -R . | less > /dev/tty
else
fun
while [ "$term" == "a" ]
do
fun
echo "//usbterminal//" > /dev/tty
break;
done
fi

I am taking scripting seriously and have managed to get this far on my own with a few suggestions from unix.com.. I would really like to understand the theory behind brackets.. Smilie


thanx moxxx68
# 2  
Old 09-24-2004
Error just to clarify...

Smilie in the script I am comfortable with the barckets around the test conditions and so on.. but as far as the brackets that go around the if then fi blocks and so on, i am not sure where to place them.. I have some general idea from studying c programming.. but i am not having the same success with brackets in shells as I am having with c programming.. an example would help...
thanx moxxx68Smilie
ps.. please use previous example so i can get some rough idea of what i am doing wrong..
# 3  
Old 09-27-2004
Most programming lanugages allow for brackets or parentheses for clarification purposes...

But they are usu not required by many languages. Be careful when using parenthesis too often, as you might become confused and have an odd one which will cause much hairpulling on your part to debug.


Many "shell" languages dont use braces or parenthesis, they use the logic structure to open and close logic statements...

if

fi

case

esac

if
then
elseif
fi
fi
# 4  
Old 09-27-2004
MySQL appreciate the feedback!!!!

Smilie infact after looking through a few posts on the sites I didn't see the use of braces in a script so i figured you can do without them, but Jim a senior member gave me an example of a script in good logic form where he used braces. and since what I wrote was close and not working because of set up, he suggested to use better format.. at the time it looked a little difficult to even set up the gawk script in # !/bin/sh format like he did without the braces.!! but if braces are not considered completely necessry all the better..
thanx a million for your input moxxx68Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Curly brackets converted to unicode in script

Is this a bash or wget issue? GNU bash, version 4.4.0(1)-release (x86_64-slackware-linux-gnu) GNU Wget 1.18 built on linux-gnu. If I run wget -O file localhost/{2..4} from the command line, it will download pages 2 to 4 and concatenate them to file - which is what I want. If I put this in a... (4 Replies)
Discussion started by: Ray-V
4 Replies

2. Shell Programming and Scripting

Capture the value between brackets

Hi I am having hard time getting this right and need some help. I Have 3 files, and everyone contains the following:- File1 Today, we have Name(Jack) Age(19) Class (A2) Today, we have Name(Kim) Class (G9) File2 Today, we have Name(Lee) Age(19) Class (A2) Today, we have... (8 Replies)
Discussion started by: samsan
8 Replies

3. Shell Programming and Scripting

Brackets

Hi all. i need a small help. i have written an exit code, which will check whether mo.sh is successful or not. if the status is >0 it will exit the shell. 1>Do you guys think it is a correct way to write? 2>what if i change the double bracket to single. how will it change the o/p. ... (1 Reply)
Discussion started by: sub
1 Replies

4. Shell Programming and Scripting

Need Suggestions to improve Perl script for checking malformed braces/brackets

Hi all, I've written a Perl script below that check and report for malformed braces. I have a UNIX ksh version and it took a couple of minutes to run on a 10000+ lines. With the Perl version it only took about 20 seconds so that is enough incentive for me to go Perl not to mention that I need... (1 Reply)
Discussion started by: newbie_01
1 Replies

5. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Shell Programming and Scripting

How to get the value in the first brackets

Hello, I am trying to write a script using ksh. And I want to get the value within the first brackets of a string. For example: 14/04/11 11:35: 00 This is (nn) from the earth. Then i hope to get nn in this case. Can any one advise me how to implement it? Thank you very much! nn (2 Replies)
Discussion started by: n_n
2 Replies

7. Shell Programming and Scripting

Get value between brackets

Hi I am having hard time getting this right and need some help. I Have several log files, and everyone contains the following 3 lines at the end: 4 ETW000 Disconnected from database. 4 ETW000 End of Transport (0000). 4 ETW000 date&time: 13.01.2011 - 08:03:28 I need to capture the value... (7 Replies)
Discussion started by: nimo
7 Replies

8. UNIX for Dummies Questions & Answers

question about brackets ()

Hello guys, I'm brand new to UNIX. I've installed Cygwin as recommended, but here are some problems. Well, man command doesn't work and I also don't know how to create a file or even how to type (). With () the program gives me an error message. Please tell me how to do all these things. Best... (4 Replies)
Discussion started by: wadem
4 Replies

9. UNIX for Dummies Questions & Answers

usage of brackets for if

Hi, I would like to know about the usage of brackets to negate a set of boolean evaluations an equivalent to what i am trying is below if or || ] ] then echo"valid time of day" else echo "invalid input" exit fi the bracket structue as mentioned doesnt work .. i am using ksh.... (4 Replies)
Discussion started by: lakshmikanth
4 Replies

10. UNIX for Dummies Questions & Answers

square brackets

I would like to substitute a phrase which contains square brackets. change TO how? Thanks (2 Replies)
Discussion started by: gilead29
2 Replies
Login or Register to Ask a Question