Programming :: Bash If *sometimes* Fails To Detect Embedded Newline
May 21, 2011
Using xsel I pass a selection into a variable. I then check that the variable includes an embedded newline to be sure that the selection returned by xsel is complete. If the selection content preceding the newline is just a single word, the check fails to detect the newline, thus
I have bash script which has lots of echo statements and also I aliased echo to echo -e both in .bash_profile and .bashrc, so that new lines are printed properly for a statement like echo 'Hello World' the output should be I even tried using shopt -s expand_aliases in the script, I am running my script as bash /scripts/scriptnm.sh; if I run it as . /scripts/scriptnm.sh I am getting the desired output.
How one could determine (for use in a Bash or Python script) which device (eg /dev/sda1, /dev/hda1... etc) a ramfs was loaded from when booting from a USB drive.
I have a RIPLinux/Tinycore live USB disk that automatically needs to run a script that is stored on the same USB drive but not part of the RIPLinux/Tinycore image. (Please note that I do not want to put this script into the RIPLinux image.) I therefore would like to remix the RIPLinux/Tinycore ISO to automatically run this script once it has started up. After RIP linux has booted I would like to automatically mount the USB drive that RIPLinux/Tinycore was booted from. I need help detecting which device this is.
I have a Bash script that runs other bash scripts. If the parent code fails, is there any way for me to also kill the child code?That kills any multiple instances of a script if I run it more than once. Is there any way I can just modify this into something that prevents the child code from running/continuing from running if the parent stops from an error?
When I am adding removing packages to get more hard drive space, this is not the first time I left too many pages open and it crashes on me. My son would fix it by typing in the terminal sudo something, but I want to know how to do this. The only thing not working is the add/remove packages at the moment. Here is what it said, E:dpkg was interrupted you must manually run 'dpkg--configure -a' to correct the problem E: _cache-open()failed please report. Please, could someone tell me how to get the default back or whatever. When I type in the terminal, it refused my password until I tried several times, plus, it finally says in the terminal No such command. Bash. No such command. I am hoping this question is one you do recognize the answer for.
I tried using Yum to remove the package. Like this:
To remove or uninstall a package:
Code:
yum -y remove ,package name>
Terminal goes: Bash syntax error near unexpected token `newline'
I am running Virtual Box Ubuntu Linux 2.6. Connected to my PC is an embedded board running debian 2.6.32. I have ip forwarding on at my virtual box. From my embedded board I can successfully ping www.google.com. I want to download and install some packages but when I try apt-get I get the following: I've flailed away at this for most of the day
I am trying to fix a perl script, and I really suck at perl. But I think this problem will be easy for people who know it.
The problem is, I have an old setup script someone wrote many years ago. It fails if the standard shell is dash and not bash. The only way I've gotten it to work is to point /bin/sh to bash. I looked thru the script and it uses "system" many places, and I think that's the problem.
I searched for it and found this link:url
My plan is to include this function:
Code: sub system_bash { my @args = ( "bash", "-c", shift ); system(@args); } Then I could simply change all calls to system into system_bash and it should work?
The parameter to the system calls is usually some variable. What if the parameter is a list already? Do I need to test for it somehow, and if it's a list, prepend "bash" and "-c" to the list? How do I do that?
In the script there are lots of places like this:
my $error = system($cmd); if ($error) { die/warn "some error message"; }
Shouldn't there be a return in the system_bash function?
I'm writing a script to replace some text that exists in about 50 .lex, .y, and .cc source code files, sometimes more than once in a file. Sometimes the text is in a multiline C comment, and other times it's within a multiline C string.
I use sed to grab the start and end of each line and wrap the new text in the old whitespace and/or quotes and Problem is, sed is changing the characters into a newline.
Is there a way to tell sed to not process escape sequences? I tried using several variations of
Code:
To no avail. Or could it be bash?
I would give up on the script and do it by hand, but this is something that I must do from time to time.
Here's the function which replaces the first occurrence found:
Code:
When $post is printed by echo, it shows the - but by the time the file is on disk, it becomes a newline. What should I do to ensure that it stays as the characters ?
I want to create an alias or function that when used prints something like this on the command line so I can further modify it before pressing enter myself.
Code: $ FILE=exercise1; cc -o $FILE $FILE.c && ./$FILE; FILE= The idea is that I'm studying c and want to change the name of the file once instead of
I would like to be able to connect to a machine, list a directory, wait long enough for me to see the results then move on to the next machine.This is failing:
I am running a Java application on the command line bash terminal under Mint Debian. I have JDK1.6.0_22 installed 64-bit, and the OS is 64-bit too. I have a few JAR files in the directory and a few native LWJGL libraries. When I run the application using the command line, all works fine. Lets assume my directory where the files are is called /home/riz/MyGame. I change to that directory and this is the command I use code...
I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.
I start with something like:
Code:
I want to replace it by something like:
Code:
(I need to paste some lines)
As I need to do this (very) often I want to use a shell script.
my update today failed, because the packages raydium and maniadrive depend on libphp5-5.2.9.so, which is provided by php-embedded, which is (apparently) not in the fedora 64bit repository There does however seem to be an i586 version...
I can't get x to work with a mouse so I have to use a windows computer to do that from for now. The problem is I remember there being something about windows using a newline AND carriage return and linux just using a newline. I was about to cut and paste code but the lines go on and on instead of breaking off where they did in linux. I was going to write a perl script but don't know how to add a carriage return to the end of each line.
I'm having a hard time figuring out why the program posted below prints an extra newline every time I type the enter key.This program is using the master pseudo-terminal to send the password and receive the output from the slave(connected to the passwd program).I suspect this has to do with the terminal line discipline(s)(2 considering the master and slave), but I can't really understand why.I have tried turning on/off several terminal special characters but to no avail.
Is there a way to use exec, but if exec fails to go on with the script?
Example:
Code: #!/usr/bin/env bash exec startx echo "Starting of X failed"
If startx fails, the echo will be seen on the screen. I tried all kind of stuff, but guess it ain't of much use to post it here. I searched the web, but searching for "exec and bash" in one sentence does give results which are not what i am looking for.
I'm trying to get sound to work on an embedded board. The boot says ALSA is present and sound chip is present. So I try to open the device with:
The hardware manufacturer assures me the device is hw:0,0 so I set device to:
This gives me:
So I'm presuming the advice that I use hw:0,0 must be wrong? So I need to find a way of working out what the device id is. I've tried default, no effect, then tried the command asoundconf list, which returns an error. I'm using a min linux build on an embedded system (busybox) so is there a way to find my sound device.
I want to be able to time how long I spend in front of a terminal. I'm thinking the best way will be to have some sort of timer that starts and stops when the terminal gains/loses focus. And it will have to work with multiple terminals...
I'm trying to change to a subdirectory: Code: tony@advent:~/scratch$ cd Home-Arch bash: cd: Home-Arch: No such file or directory
So I list the contents of the current directory: Code: tony@advent:~/scratch$ ls duhome Home-Arch qcad_1.dxf qcad_1.svg runme stdout
OK, I assume I have mis-typed the subdirectory name in ways I cannot detect, so I copy the sub-directory name from the output of the 'ls' command, while within the terminal window, and paste it into the next 'cd' command:
Code: tony@advent:~/scratch$ cd Home-Arch bash: cd: Home-Arch: No such file or directory
I browse the directory and sub-directory in Nautlius - everything is there where I expect it to be. The folders/files are not hidden. What is happening here?
I am attempting to install debian for the first time on my pc that has no cdrom drive. I downloaded the Jessie CD image and wrote it to a 4GB stick, it didnt work. Then tried the netinstall image but face the same issue.
To write the usb stick I used unetbooting first, then tried win32diskimager and finally tried DD while stick was not mounted
Issue is still the same: I boot from the usb and after selecting language and keyboard it fails to detect cdrom drive (no drive at all in my pc). Same behavior using normal or expert mode.
Im also unable to manually specify the drive (it looks at /cdrom and I wanted to change it to the usb stick itself or mount usb to /cdrom but I cant find my stick in /dev)
Ubuntu 9.10 comes with rt2870, the driver for my Zonet ZEW2545, and I have had to blacklist rt2800usb in /etc/modprobe.d/blacklist.conf in order for rt2870 to work. My network adapter is able to attempt to connect to my router, but after 10-40 seconds it tells me I am disconnected again. This adapter works fine on windows.
I am developing a program in a system where the Linux does not take care of the sync command automatically. So I have to run it from my application always I save some data in the disk, which in my case is a 2GB sdcard. It is true that I can make the operation system takes care of the syncronization, using a proper mount option, but in this case the programm's performance drops drastically. In particular I use the shelve module from Python to save data that comes from a socket/TCP connection and I have to deal with the potencial risk of the system being turned off suddenly Initially I wrote something like that to save data using shelve:
But that takes too much time to save the data. Note that I use the sync from the OS every time I close a file to prevent data corruption in the case of the "computer" being turned off with data even in the buffer. To improve the performance I made something like that:
Code:
def saveListData( list ) fd = shelve.open('file_name', 'c') for itemVo in list: fd[itemVo.key] = itemVo fd.close() os.system("sync")
Thus, first I saved an amount of objects in a list then I open the file and save the objects. In this way I have to open the file just one time to save a lot of objects.However I would like to know if adding a lot of objects before closing the file would increase the risk of data corruption.I known that turning off the system after fd.close() and before os.sync may cause problems. But what about turning off the system after
I'm trying to write a small script and there's one part of it that makes me sick:
Code:
ifconfig eth$num down sleep 6 ifconfig eth$num hw ether $mac ifconfig eth$num up
The problem is that the ethX interface doesn't go down immediately after the first line is executed. So sometimes the change of MAC is called while ethX is up, no matter how big is the sleep time, which results in an error. Is there a way to make this work right?
just bought an adaptec 39160 PCI scsi controller and 34Gb drive and installed it on my computer.When i Booted it up a utility thing ran which said 'detecting array' and it found the drive and its size etc. it didn't go any further to allow my system to boot, so I rebooted and pressed CTRL + A to enter the adaptec scsi config. I changed something in there to make the disk non bootable (i Think) and rebooted the system.
It now hangs at :
'Detecting Array .....'
and does not show the drive details or the CTRL + A option to enter the utilities. So the only option I have had is to remove the adaptec controller ( and the system boots fine) the mother board is an Abit an8 ultra - probably about 4 years old and cpu is amd 64 I guess i have broken it and my remedy would be to reset the default options on the adaptec controller, but you can probably guess I have v. limited knowledge and have not used scsi before.
Having trouble installing 'Squeeze' 6.0.1a-amd64-netinst on a new AMD64 system.The installer boots and runs fine until it gets to hard disk detection. Then it hangs for about 20 minutes showing a blue screen, during which time the HDD-activity light flickers every 5 seconds. Eventually it says it can't detect a hard disk, and displays a (longish) list of possible drivers; no idea which, if any, would suit.Anyone else installed (successfully or otherwise) on this combo?