Programming :: Bash Compound Tests And Parenthesis
Mar 24, 2011
In C++ language, we can do the following compound tests,
Code:
std::string a, b, c, d;
if ((a == "Yes" && b == "Yes" ) || (c == "Yes" && d == "Yes")) { ... }
In bash scripts, how can we do the parenthesis around compound tests?
Code:
if [ "$a" = "Yes" ] && [ "$b = "Yes" ] [ "$c" = "Yes" ] && [ "$d" = "Yes" ]; then
...
fi
Is there any method for placing translations in parenthesis at first occurrence? I need something similar to the acronym package, but instead, storing translations and printing brackets only after the first occurrence.
E.g. (pseudo-code):
Results in:
Do you like to eat bananas (xiangjiao)? No I don't like to eat bananas.
I have a file with several parentheses, both () and []. All of them should be closed, but apparently, one of them is open. In order to run a program, I need all of them to be closed... For example, if I write: ((bla (bla (bla)) I would have two parentheses missing. That's what I mean. But I have several parentheses in the file... it would take me ages to do it manually. Is there a way to check which parenthesis is open? can it be done?
I'm trying to look through a big folder of air photos to see if there are some world files that have duplicate coordinates. I want to find *.jgw files that have 123 in line 5 and 456 in line 6. I first thought grep could do this for me but grep 123 *.jgw|grep 456 finds only files where 123 and 456 are on the same line. Is there a sed trick for this?
I have filenames like such: abc (e).doc And I want to rename them to abc.doc I have a directory full of files names like this. How can i do this using the sed command? I have looked online for about 2-3 hours now and am frustrated that I can't find an answer.
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
Code: #!/bin/bash trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c echo "Press ctrl+c during 5 sec loop" for ((i=0;i<5;i++)); do
[Code]...
How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!
When I see a typical reference to a Unix manual, it often follows by a number surrounded by parentheses. For instance syslog.conf (5). I am sure this means something, but Googling it is impossible.
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.
Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?
I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.
Fifteen years ago buying a new computer was easy, magazines provided comparative tests of PCs for one's budget. Now typical magazine specs are not high enough for my needs:
I need a PC that can duplicate a 5 gb file in less than 10 seconds.
Where do I find comparative tests for PCs at this very high end?
Notice that some tests in webcache will fail on freebsd when -O is turned on. This is due to some event reordering, which will disappear when -g is turned on. I tried to run the test individually one after another, but that is too time consuming, it prompts for permission after every test and thus runs many test & opens a lot of xgraph window. The tests I run so far individually, agreed with the reference output. Now I am wondering, should I report a bug about it, or should I hire a kid to run those failed 40 tests( which require hitting the ENTER key 1200 times,maybe ), or what else should I do.
i have a OpenSUSE 11.3 with Gnome desktop ( core i5 processor, 2 GB DDR3 RAM ) want to run memtest, plz advice me which prog is best for it and where to find documentation or videos.Moreover is there any tests for motherboard / processor
I have a USB sound card that works sometimes with Firefox and with the VLC media player, but in the middle of a Gnome session it drops out and the sound starts coming from the internal card. In the Gnome Sound Preferences USB Audio is still selected and the test sounds still come loud and clear from the USB card, but the applications are ignoring this and have switched to the internal card.
The Gnome Device Manager shows the UA-4fx card and under it "USB Audio ALSA playback" and "USB UA4FX ALSA Control Device" devices are listed. I want to make the USB card the default for all applications and have internal card take over only when the USB card is unplugged.
Ultimately my DB will run in VM2 and any DB requests coming in at 2055 of VM1 should be forwarded to port 2055 of VM2. Since I do not yet have a DB running I am trying to test with netcat.
I'm doing some tests and playing around with postfix in a test squeeze server. What I want to achieve is a postfix mail server using ports 465 and 587 with smtp authentication to send mails. I followed this howto: [URL].. and I'm using a php script with pear functions to test sending emails to a gmail test account of mine. This is the script:
<?php require_once "Mail.php"; $from = "Webmaster <webmaster@server>"; $to = "My Name <myaccount@gmail.com>"; $subject = "This is sent with pear as a test"; $body = "This is the body of the message";
Epson stylus d88 recognised by 10.04 no tests or maintenance available in local host and obviously not printing. It's like it's there but they cannot talk to each other
I need to rename the resulted searched files from a loopI have the following code:
find . -name DOC* | while read i do find $i -type f -name '*.txt' done
basically, I am searching for all txt files inside any folder starting with DOC name.this code is working fine with me.I need to rename those .txt files to .txtOLDOS: Ubuntu 10.4Bash shell
I am trying to write a bash script that sources another bash script. Essentially, I need a few lines to check to see if a certain variable is set. If not, I set it manually, and then source a scripts with that variable in the path. I wrote a test script to try it, but for some reason the last line does not work. Here is what I wrote:
#!/bin/sh source ~setupdir/setup.shrc #just a test, this line works echo ${#SETUP} # prints 0 if setup is not set, which it isn't if [ ${#SETUP} -eq 0 ] then SETUP="~setupdir" fi echo $SETUP # prints ~setupdir
i'm in the process of learing C++. currently i'm creating shell scripts to get things done. i'm just curious how, as a programmer using C++ you would get a similar job done.as an example i have a script that takes the contents of files, pipes it to some sed and awk commands, which is piped to create a new file. that file is then imported into a mysql database.if you were going to do this in C++, would you call the sed/awk programs to modify the file, or can it be done within the program itself? i'm probably jumping the gun here because i've just started learing about pointers so this is above my ability
A friend has intalled Linux after a load of problems with windows. He very kindly installed my Edirol UA25 soundcard, and when i click 'test' on System-preferences-sound, it indeed plays a sound. The problem is that when I try to play anything from the internet on firefox, or any sounds in VLC, or any other application, it doesn't work. I believe I'm running Ubuntu Studio, version 8.04, but I am not sure. I have an Athlon 64 bit processor if that's relevant.
Creating script that converts hex to dec. But without using bc calculator or other methods that could convert it in one line. I need to make something like this script that converts dec to hex.
I have a basic awk script that can read a file named 'server_info' and output to the screen which fax lines are not working. Now I want to make the script execute commands instead of printing to the screen but I am having trouble... This is better explained by my code below:
test.sh Code: #!/usr/bin/awk -f # #The name of this script is test.sh
Code: #!/bin/sh #System commands and other configurable. IPT=/sbin/iptables IP6T=/sbin/ip6tables IPST=/usr/sbin/ipset MODP=/sbin/modprobe GET=/usr/bin/wget INT_NET=192.168.1.0/24 .....
I can find lots of tutorials in how to use if, then, else. However, how do I define a variable inside the function? SEE>> Code: for c in $ISO Also, am I using the 'test' command correctly( -/+ week as valid test)?