bash scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash scripting
# 8  
Old 04-13-2011
Quote:
Originally Posted by ctsgnb
Code:
$ wc -l <myt
       2
$ wc -l <myt | xargs
2

But i suppose if you point it out to me, it just means that my xargs is useless because the simple calculation and expansion will remove the leading tab anyway ...
I don't think it's removed, since everything that happens within arithmetic expansion is treated as if it's double-quoted. It's just that whitespace is allowed between operators and operands within $((...)).

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 9  
Old 04-14-2011
good night my friends!!! thank you sooo much for all you've done for me!!
I'll be here tomorrow again because I think that I will have another question!!! Smilie
bye bye and thaaaanks!!!! Smilie

---------- Post updated at 06:34 PM ---------- Previous update was at 06:31 PM ----------

good night my friends!!! Smilie Thank you sooo much for all you've done for me!!!
I'll be here tomorrow again, because I think that I will have another question!!! Smilie
bye byeee Smilie

---------- Post updated at 06:34 PM ---------- Previous update was at 06:34 PM ----------

haha two times Smilie

---------- Post updated at 06:36 PM ---------- Previous update was at 06:34 PM ----------

hahaha two times!! Smilie

---------- Post updated 04-14-11 at 09:48 AM ---------- Previous update was 04-13-11 at 06:36 PM ----------

Hello again!!!
Can anyone tell me please what is the job of the command:
Code:
tr -cs "[:alpha:]" "[\n*]" < inputfile

I read sth on the web but I don't get it!

Last edited by Franklin52; 04-15-2011 at 04:32 AM.. Reason: Please use code tags
# 10  
Old 04-14-2011
Contiguous non-alphabetic characters are replaced with a single newline.
# 11  
Old 04-14-2011
oookaaaay!!!
now I have a different problem.I want to generate a number from 1 to 10 and I have written this:
Code:
x=$RANDOM
y=$RANDOM
num=`exp \($x32768+$y\) % 10`

and I have errors... Smilie

---------- Post updated at 11:59 AM ---------- Previous update was at 11:57 AM ----------

Code:
num=`expr \($x*32768+$y\) % 10`

this is what I have written in reality ...

---------- Post updated at 12:01 PM ---------- Previous update was at 11:59 AM ----------

error:
expr: non-integer argument

Last edited by Franklin52; 04-15-2011 at 04:32 AM.. Reason: Please use code tags
# 12  
Old 04-14-2011
What is your system? What is your shell? Unless you're stuck using a really old shell there's way better ways to handle numbers than expr.

expr is thorny. It expects each individual thing to be a seperate argument, like "1" "+" "2". So (1+2)/stuff is out, that jams it all into one argument. So is "1+2". 1 + 2 works because of the spaces.

expr has the % operator for remainder or modulus, 1 % 10 is 1, 9 % 10 is 9, 10 % 10 is 0, 11 % 10 is 1, etc. So you can do $RANDOM % 10 to get a number from 0-9, and add 1 to it to get a number from 1-10.

VAL=`expr $RANDOM % 10 + 1`
# 13  
Old 04-14-2011
I use th bash shell... ok... if I want to generate a number for example from 1 to 100000, then why these commands:
Code:
x=$RANDOM
y=$RANDOM
num=`expr \($x * 32768 + $y\) % 100000

have the error:
expr: syntax error??
I think that I wrote them correctly... according to the colors...

Last edited by Franklin52; 04-15-2011 at 04:33 AM.. Reason: Code tags
# 14  
Old 04-14-2011
Quote:
Originally Posted by Corona688
expr is thorny. It expects each individual thing to be a seperate argument...
Indeed. And the fact that many components of the expr(1) syntax are shell metacharacters compounds the hassles, since one can't simply stuff the entire expression within strong quotes.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Bash Scripting

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Try running 'phone4 xyz' and see what happens. Modify your program so that if no matching name is found, an... (1 Reply)
Discussion started by: OmgHaxor
1 Replies

2. Shell Programming and Scripting

bash scripting

same script: 1- i am using grep to find a string called: tinker panic 0 in a file /etc/ntp.conf if the string is not there, i want to add the strings in /etc/ntp.conf file in the first line of the file. if not do nothing or exit. 2- also i want to add # in front of the following lines in... (0 Replies)
Discussion started by: lamoul
0 Replies

3. Shell Programming and Scripting

bash scripting help

Hi Guys i have a <script?> that spits out the location of each printer using snpget here is the code for i in `sed -n '/Start Printer/,/End Printer/p' /hosts/blah/etc/dhcp/hosts.conf | awk '!/^#/ {print $2}' | egrep -v \... (2 Replies)
Discussion started by: ab52
2 Replies

4. Shell Programming and Scripting

Bash scripting

Try to imagine a flag: nnnnx nnnxx nnxxx nxxxx now imagine how it will output: 4 times the "n"and 1 times "x" 3 times "n"and" 2 times" x " .. etc. .. rhombus is the same only instead of "n" is there gap "and " x "is a few times to form the correct shape Can you help... (3 Replies)
Discussion started by: krcek12
3 Replies

5. Shell Programming and Scripting

bash scripting help

have this code but when i run it i get this error ./pulse: line 2: and here is the code #!/bin/bash if ; then pulseaudio -k; fi what am i doing wrong thanks Adam (5 Replies)
Discussion started by: ab52
5 Replies

6. Shell Programming and Scripting

please help with Bash Scripting????

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name) ... (2 Replies)
Discussion started by: eminjan
2 Replies

7. Shell Programming and Scripting

bash scripting help!!

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name)... (3 Replies)
Discussion started by: eminjan
3 Replies

8. UNIX for Dummies Questions & Answers

Should I do a bash scripting course?!

Hello, I'm confused (oh, yes). I'm running Linux at work. When I type 'echo $SHELL' I am told that I'm running tcsh. In /bin I note that both tcsh and bash are listed. Question 1: Can I swap to run bash rather than tcsh and, if so, how will this affect my system? Is there any advantage to... (6 Replies)
Discussion started by: macpete
6 Replies

9. Shell Programming and Scripting

Bash Scripting

Hello there peeps: There is a little piece of bash shell scripting problem i have, which i was hoping you could help me with. #!/bin/bash stored_word() { case $(( $$ % 8 )) in 0 ) echo "energy";; 1 ) echo "touch";; 2 ) echo "climbing";; 3 ) echo... (3 Replies)
Discussion started by: keyvan
3 Replies
Login or Register to Ask a Question