General :: IF Statement - Not Getting Equal Results From All Cases
Jun 6, 2011
I'm a bit stuck with IF statement. There is the code:
#!/bin/bash
# Variables
VAR1=test
VAR2="echo $VAR1"
# Case 1
echo Case 1
if [ test == test ]; then
echo "equal"
else
echo "not equal"
fi;
echo ""
# Case 2
echo Case 2
if [ "VAR1" == test ]; then
echo "equal"
else
echo "not equal"
fi;
echo ""
# Case 3
echo Case 3
if [ "VAR2" == test ]; then
echo "equal"
else
echo "not equal"
fi;
echo ""
When executed, why case "2" and "3" differs from case "1"? Where am I wrong and how to solve this trouble? (my aim is to get "equal" from all cases).
View 2 Replies
ADVERTISEMENT
Jun 28, 2010
We are building our C++ project in Kdevelop IDE. Every time we run "Run Configure" from the "Build" menu, a file named "libtool" gets automatically generated. This file contains a statement as "ECHO="echo"".f we run "Automake", without modifying the "libtool" the system hangs and theputer needs to be restarted.Therefore every time we run "Run Configure" we need to include the line "echo="echo"" below the statement "ECHO="echo"" manually.I think a script can be written which does the above on its own.I am not a shell script programmer, I know the good tutorials for shell scripts are available on the net, but learning scripting only for this task would be time-consuming and painful.
View 4 Replies
View Related
Oct 6, 2010
I've written a simple perl code to learn switches in perl.My code is pasted below,
#!/usr/bin/perl
$opt = 1;
switch($opt) {
[code]...
View 3 Replies
View Related
Apr 6, 2010
I'm timing how long it takes to run a command foo. I'm looking to append the results from the time command to a file, and discard the results from the foo command. I tried the following, but it didn't do what I want:
$ time ./foo > /dev/null >> output_from_time_command.txt
View 1 Replies
View Related
Jan 25, 2011
If I only want to let a user be able to login via telnet a max number of times equal to 2 how would I go about doing this?I have found this little tid bit:per_source = 2but that only allows 2 connections from the same source (i.e. network) and that would not work. For some reason our telnet sessions are not dying off after a user has shutdown their PC and then the next time they login it adds another telnet session.
1. user1 31300 /dev/pts/409
2. user1 27539 /dev/pts/539
3. user1 18042 /dev/pts/316
[code]....
View 4 Replies
View Related
Jul 12, 2010
the script below prints the pwd of where I want to be. after the fi it puts me back at the original dir. just writing these scripts to understand what's going on.
#! /bin/bash
if
[ -d mydir ]
then
cd mydir/ && pwd
fi
View 4 Replies
View Related
Feb 2, 2011
I want to have an if statement that does multiple things:
Code:
if [....] ; then
1=...
2=...
[code]....
View 3 Replies
View Related
Jun 23, 2010
An arbitrary matrix can be solved using Gauss-Jordan elimination with O(n^3) complexity. A tridiagonal matrix (i.e. a special type of matrix) can be solved using Gauss-Jordan with O(n) complexity. That is, a for an arbitrary matrix, Gauss-Jordan is a cumbersome algorithm, but for a tridiagonal matrix, the algorithm can be expressed as a loop and a simple formula. If I were writing, for example, a compiler or some optimization program, is there a way to test the problem to see if it has become less complex, so I can express the algorithm more simply?
View 2 Replies
View Related
Jan 23, 2011
$ uname -a
Linux a 2.6.35.10-74.fc14.i686.PAE #1 SMP Thu Dec 23 16:10:47 UTC 2010 i686 i686 i386 GNU/Linux
$ lsb_release -a
LSB Version: :core-4.0-ia32:core-4.0-noarch
[Code].....
How can I set a pattern that will output a filename equal to the original filename? E.g.
something.mp3 → something.ogg
And why isn't this implemented in SoundConverter?
PS: {Filename} doesn't work.
View 1 Replies
View Related
Jul 11, 2010
I want to have the System Bell ring when a process is over say a download. First I created a file named 'beep' that plays the System Bell. Because the System Bell rings by hitting cntrl-G the 'beep' file looks like this.
Code:
echo ^G
I then give the file owner execute permission. I know that this command would serve my purpose.
Code:
[URL]
However I want to sharpen my Bash programming skills. I wanted to write the Bash script along the following logic and with the fewest lines possible. Not really a script, I want to insert this short script via command line instead of a file. Let's say the download has commenced and the PID = 16666.
Code:
until ps -p 16666
do
/root/beep
done
Now obviously 'ps -p 16666' will already evaluate to true. My question is, is there a way to maybe enclose 'ps -p 16666' and prepend some operator that inverts the condition to where until 'ps -p 16666' evaluates to false then run /root/beep?
View 5 Replies
View Related
May 14, 2010
I need to to write a bash script using an If...Then...Else statement that will accept a day of the week from the command line what do I do or where do I go.
View 2 Replies
View Related
Oct 10, 2010
On Ubuntu 9.10 I installed Python 3.1.1 successfully with Synaptic Package Manager. However the Python interpreter cannot find my scripts, currently in /home/dave/pycode. This appends _temporarily_ but python remains clueless about location of my scripts. Searched Internet and some speak of .rc or .bashrc or .profile..files. Found some of these and opened with Komodo : they are Linux script files and I am clueless as to how to modify.Currently I can import my scripts only if I change to the /pycode dir before running.Lutz's Python book says to change PATH file - Ha .Sobell's "A practical Guide to Ubuntu Linux" is no help. Ubuntu's own on line help is worth less than a fart in a hurricane. Ubuntu's gedit would not even open bash.bashrc.
View 7 Replies
View Related
Mar 15, 2010
I am facing problem with the following script. Could you please look into this.echo 'Enter Staging number' case $STGNUM in
1)
for i in {'stg1-greg','stg1-marsha','stg1-peter','stg1-jan','stg2-greg','stg2-marsha','stg2-peter','stg2-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/stopwf.sh;done;
[code]....
View 2 Replies
View Related
Sep 13, 2010
I am trying to create a "GUI File Transfer " Application , for transferring the files within the network. For That I will obtain User name, Password through the GUI, I will have to append username and password in a single line and run it . I am facing difficulties in exploring the "command",
View 4 Replies
View Related
Oct 25, 2010
I am having a weird problem where if I don't touch the mouse or keyboard after logging on, the power manager settings are being ignored. I disabled turning off the display and screen saver from the Gnome utilities, but after about 20 minutes my screen blanks and my wireless network connection gets disconnected. This is on an HTPC, so I'm usually not near the mouse or keyboard, and unfortunately button presses from the remote control don't count. Media players like MPlayer will prevent the screen from blanking, but if I'm listening to music (where the music is served over the network from another computer), this means that the screen will go blank and the music playback will freeze as the network connection is lost. If I touch the keyboard just after booting it doesn't blank the screen or disconnect my wireless, but when I forget it's very disruptive.
I am running Debian Testing (Squeeze) with a Gnome desktop environment. I'm using gdm3 to log in, but I have it set up to automatically log me on. (I use gdm on my desktop, also with Squeeze, with it configured to show login screen instead of automatically logging me on and it still displays that behavior) I have attempted the following to resolve this issue to no avail:
Disable DPMS for my screen and monitor in /etc/X11/Xorg.conf Set all the timeouts for blanking, power down, etc. to 0 in /etc/X11/Xorg.conf Flat out disabling the DPMS extension. (so it's still blanking, even if it's not actually turning on power saving mode) Putting "xset s off" in ~/.xinitrc Disabling powersave with setterm in ~/.xinitrc
Removing gnome-screensaver and gnome-power-manager from the startup items.
Edit: Actually, the wireless issue seems to not be related. It disconnected again, and after some searching with the error message I saw in dmesg, it looks like others have been having the same issue. It seems to have been coincidental that it was acting up when I was testing the screen blanking issue, and hasn't given me as much trouble lately, so it seemed like it was correlated.
View 3 Replies
View Related
Jan 21, 2010
right now i'm doing a find . -type d -iname "z*" to find all folders who's name starts with z or Z.
Is there a way I could with one command find all folders who's name starts with the letters M through Z, without having to do the same command over and over and just changing the letter each time?
View 15 Replies
View Related
Apr 23, 2011
as the title,I want learn how it works.
View 1 Replies
View Related
Jan 6, 2011
Most of the time my wireless works very well, connecting lightning-fast on boot with AC power. However here are two problems that I have noticed to-date: 1. Wireless will not connect if I boot on battery power. It won't connect even if I plug in the AC cable and do a reboot. Only solution is to reset the router (unplug power cable, wait, plug power cable). 2. Wireless will not connect after a Suspend, whether battery power or AC. Again, only solution is to reset the router. Another computer, running Windows XP, do not have connection problems (yes, wireless). It is quite strange, maybe some power management settings are interfering with networking? I have both laptop-mode-tools and pm-utils (re-rolled) installed.
View 2 Replies
View Related
Jul 28, 2010
Few months back I learnt a *few* concepts about bits/bytes and started writing a program for bit packing in C++. Now that program has grown upto 600 lines and I am still working on it. Yesterday I realized I missed some special cases due to which the program was malfunctioning. Now I have modified the program and it is working properly but I think If I would have designed all the possible test cases before writing the code, I would have finished the program long ago.
I. What is proper way to design the test cases before coding?
II. How should I make sure that I do not miss any cases while making the test case doc. ?
III. Does writing test cases prior to coding solve messy code issues or should I consider something else ?
View 8 Replies
View Related
Apr 21, 2010
Here's the bash script:
Code:
FILES="/usr/sbin/accept
/usr/sbin/pwck
/usr/sbin/chroot
/usr/bin/fakefile
[code]....
Notice the extra" file size" lines in there? What's causing that? I'm trying to learn more bash skills. I have no experience with awk because I have been unable to understand it's basic necessity. But I thought maybe if I try it with some test scripts I might become more interested in using it more and expand my very limited capabilities.
View 13 Replies
View Related
May 2, 2011
I am trying to use sed command to repalce one string with other but somehow replacement string contains forwards slash hence getting the error statement garbled!
[Code]...
View 4 Replies
View Related
May 23, 2010
what are use cases for static ip address for clients or servers.
View 3 Replies
View Related
Sep 10, 2010
I'm been struggling to find a way to configure suse to send audio to a receiver in some cases. Details: - Did a fresh install - Using an old SoundBlaster card (which worked in my previous version of openSuse) - I do have digital out, but only for Amarok (start menu -> configure desktop -> multimedia -> prefer "SB Live! Platinum [CT4760P], Multichannel Capture/PT Playback (IEC958 (S/PDIF) Digital Audio Output") and Kaffeine (.kde4/share/apps/kaffeine/xine-config -> set "audio.output.speaker_arrangement:Pass Through").
- I have analog sound on firefox and "test volume" on Administrator Settings -> Sound, but just can't find a way to configure those to digital passthrough (tried to copy "audio.output.speaker_arrangement:Pass Through" to .config/kde.org/Phonon-Xine.xine.conf but didn't work)
[Code]...
View 5 Replies
View Related
Mar 24, 2011
I have a .bashrc script to shorten the length of my shell path and occasionally I get the error:
Code:
I've tracked it down to this line
Code:
But can't seem to find anything wrong with it.
View 2 Replies
View Related
May 6, 2011
Im a bit stuck with a simple script that im practicing with... im trying to get my head around some simple scripting. Basically i want to write a script that will work as below: It will ask the user to enter their userid. If its correct it will say 'Correct' If its the wrong id (But the ID exists in /etc/passwd) then it will say 'incorrect' If its not a valid userid it will say 'doesnt exist'. What i have so far is:
[Code]...
# If the user enters their own userid they will get a comment saying 'correct' $LOGNAME) echo "Correct";;
# If they enter another users ID (That exists in the /etc/passwd), then they get a message to say 'incorrect userid used'. Im not sure what i need to do here to get it to check the /etc/passwd to see if the input exists in there.... im guessing some kind of simple 'if' statement to say ---- "if 'input' exists in /etc/passwd then echo "incorrect userid used"
# If its entered incorrectly and not a valid ID then they will get this comment. Again, im guessing this part would be similar to te above option..... *) echo "not a valid ID";;
Ive managed to work out how the basic Case staements work, but to add a conditional statement based on the input, i just cant figure out. I have tried looking on google, and found some help but it doesnt really explain how i check the input against the /etc/passwd.
View 17 Replies
View Related
Nov 30, 2010
This is piece of my samba configuration with LDAP
Code:
workgroup = PCPR
netbios name = SERWER
server string = Samba %h PDC
My domain name is PCPR, (workgroup name is equal to the PDC's domain name, right?) but when I execute
Code:
net getlocalsid
i get
Code:
SID for domain SERWER is: S-1-5-21-3946501231-293034350-4217055208
Why SERWER, should not be PCPR?
View 4 Replies
View Related
Oct 25, 2010
I have a router having four ethernet ports and bandwidth of this router is 500kbps. Suppose one user used one Ethernet ports only rest of Ethernet ports are free, that user should get 500Kbps. If I Add one or more user to any of the Remaining Ethernet ports how can i equally share a bandwidth among those two users ,it means each user should get 250kbps.
View 1 Replies
View Related
Jun 15, 2011
I have bees assigned a problem which states that :
sendmail-2: Wrong number of instances of process sendmail:, expected instances equal 1 but found 0
THats it...what exactly this means and how should i proceed for solving this problem...
View 1 Replies
View Related
Mar 3, 2010
how to Divide Equal Bandwidth between / Among Network Clients? e.g if there is total bandwidth = 10Mbps and only 5 clients are online then bandwidth should be divided evenly i.e each client to 2Mbps and if 20 clients are online then 0.5Mbps to each client automatically. [in windows this can be done by bandwidthcontroller software now how it can be done in linux]
View 3 Replies
View Related
Jun 21, 2010
I'm trying to install Ubuntu, Windows 7, Meego, and Android x86 for a project. Here is what I have done so far: Partition the drive into 4 primary partitions of equal size (10gb each). Install Windows7, Android, and Meego onto separate partitions, in that order. Then, install Ubuntu, hoping that GRUB automatically detects the other OS's and creates entries for them. Unfortunately, the only entries in GRUB are for Ubuntu and Windows 7. How do I get to the other 2 OS's (Android and Meego) to show up?
View 4 Replies
View Related