Programming :: Bash: Functional Difference Between Process Substitution And Here String With $( )

Mar 14, 2010

Further to solved LQ thread Bash: how to populate a list of arbitrarily named files?, what is the functional difference between feeding a loop with process substitution and feeding it with a here string with embedded command substitution? ABSG pages: process substitution, here string and command substitution. This works

Code:

while IFS= read -r -d '' file
do
files+=("$file")
done < <(find $dir -type f -print0)

[code]....

View 2 Replies


ADVERTISEMENT

Programming :: Bash - Why Is Process Substitution <() So Much Faster

Nov 25, 2010

file allids consists of 300,000 rows, each containing a 5-7 digit numeric id. file newids consists of 20,000 rows of id's. How do you explain the following timings? time: 0.07s:

Code:

diff <(sort allids) <(sort newids)
time: 1.6s:

[code].....

View 4 Replies View Related

Programming :: Variable Substitution In BASH?

Feb 17, 2011

Just a simple BASH for loop to read the file path from a text file (clean.txt) echo the variable for debug purposes, and scp it to a server I have using port 50 for SSH.

I've already formatted the entries in clean.txt to handle spaces correctly, using sed replacement.

Example from the clean.txt file:

Code:
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/20 Auld Lang Syne.mp3
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/14 Deck the Stills.mp3

[Code]....

View 5 Replies View Related

Programming :: Difference Between Init.rc Process And Normal Process?

Mar 31, 2011

Is there any difference in cpu usage for process in init.rc(runs automatic when boot is happened) and manually running process. Will these both have same priority by default...?

View 1 Replies View Related

Programming :: Substring Extraction - Bash Gives "bad Substitution" Error

Jul 16, 2010

I'm trying to use ${VAR:0:4} substring extraction described here: tldp.org/LDP/abs/html/string-manipulation.html and it works perfectly if i issue a command in bash. But when i put it in a script file and run it, bash gives me "bad substitution" error. Does anyone know how to fix it?

View 5 Replies View Related

Programming :: Difference Between /bin/bash And /bin/sh?

Dec 27, 2008

I know it's a very silly question but could someone please explain the difference between "/bin/bash" & "/bin/sh" I was under the impression that both are same but following output on my Ubuntu 8.10 is making me raise my eyebrows.

Quote:

parag@station3:~$ ls -l /bin/bash ; ls -l /bin/sh
-rwxr-xr-x 1 root root 725136 2008-05-13 00:18 /bin/bash
lrwxrwxrwx 1 root root 4 2008-12-03 21:42 /bin/sh -> dash
parag@station3:~$

View 11 Replies View Related

Programming :: Difference Between Init And Main Function In A Process

Jul 12, 2010

I have a project in which many processes run. p1,p2,p3.

->There are some .so files are included in some process when needed example ppp.so in process p1 (when ppp is needed and will go like a plugin) but it has a init () function how a process includes a init() function ?

->process p1 has main function i.e main()

->so evry process has main() right ?

what is the difference between init () and main () functoins. where is init () used and how many init() a process van have ?

View 3 Replies View Related

Programming :: Bash String Splitting Into Array?

Oct 14, 2010

I am using gnu bash 3.2I need to split the string into array like

a=this_is_whole_world.file # split [_.]
I need to split this on _ and . some thing like this
a[0]=this
a[1]=is
a[2]=whole
a[3]=world
a[4]=file

preferable using bash regex. if not sed is also ok.

View 2 Replies View Related

Programming :: Bash Concatenating String To Variable ?

Jan 18, 2011

I have a program that loops over each word in a sentence. I need to append a constant to the beginning and end of each word. It works up until the last word on the line.

Code:

Output:

View 4 Replies View Related

Programming :: BASH - If Variable -eq String Not Working ?

Jan 24, 2010

Here is the code:

Code:

How ever when I run this script I get the following error

Quote:

I just don't get it, I have racked my brain trying to figure out every combination of how I should write this if statement and I can't get it to work.

View 2 Replies View Related

Programming :: Bash Regex String Extraction?

Jun 10, 2011

Code:
g echo ${mm[$j]}
4 BashNotes

[code]...

View 2 Replies View Related

Programming :: Bash Removing String From File?

Aug 7, 2010

I am trying to remove everything before my string code...

View 9 Replies View Related

Programming :: Using Bash To Append A String To Array?

May 19, 2011

I have the following function that does not iterate through the array I want to be able to do some manipulation on each element in the array[@].it appears the below array has only one item in the array whereas i want the array to have 3 items hence the loop three times printing the message Any ideas why this is not happening ?

function foo() {
name =$1
array=( "$2" )

[code]...

View 5 Replies View Related

Programming :: Get And Process Stuff From JSON Encoded Serialized Data String?

Apr 2, 2010

I have this JSON encoded data, which I want to efficiently parse (i.e. fast, with minimal system resources). I don't want to use a/the shell any more than necessary.

Here's a snippet of what the raw serial data looks like:

Code:
[{"num":1,"name":"1","visible":false,"focused":false,"rect":{"x":0,"y":0,"width":1680,"height":1050},...blah blah..
So that's fine. I currently have at least two ways of parsing it:

This Perl method (which I don't much care for because I'm not much into Perl, and because the output is not much more useful than the raw form, and imho even more cryptic):

Code:
sasha@reactor: <produce data> | perl -MData::Dumper -MJSON::XS -E 'say Dumper(decode_json <>)'
$VAR1 = [
{
code....

# Which means: at x=1680, draw a 20x20px grey block, then back up -10px and draw a "1" on the block.I figure that the two awk's I've used can be combined into one -- but I began having problems with removing the single quotes if I did it within the awk, which is why I stuck a `tr` in the middle.

I know this sucks. So, if someone has some ideas or thoughts on something else to do with this JSON data, that's less convoluted that where I'm currently going, I'll be happy to hear about it.

PS - I know this whole post is possibly hard to understand -- if you need more info (you mean you're interested in this mess?? )

View 13 Replies View Related

Programming :: Difference Between Shell And Bash Scripts?

Sep 25, 2010

Whats the difference, and when do you use which?

View 2 Replies View Related

Programming :: Difference Between Formats In BASH Shell

Apr 30, 2009

I searched around but I can't get a good handle on the difference between the following formats in BASH shell.

$VAR
$(VAR)
$((VAR))
$($VAR)
$(($VAR))

Can someone explain it, or point to a clear, concise document explaining it?

View 3 Replies View Related

Programming :: Bash: String Verifier Doesn't Work

May 26, 2011

I'm currently learning bash programming and am trying to create a program to maintain a list of people. Here is the code so far:

Code:

#!/bin/bash
# Namelist
clear

[code]....

As you can see, I attempted to build in a protective measure to prevent duplicate entries using "if grep -Fxq "$FN $LN" /home/andrea/namelist.txt", FN and LN being first name and last name as you can see in the first read operation. However, this fails to actually work. Demonstrations:

[URL]

It saves the details to the file rather than displaying the error message, or in other words, it doesnt check the file properly.

View 4 Replies View Related

Programming :: Bash Thinks String Variable Is A Numeric One

Jul 7, 2011

Bash 3.1.7

Code:

Code:

Code:

I think read A1 A2 makes A1, A2 string variables. Then, when A2 gets the value 01, '01' should be a string. But for some reason bash takes it as numeric. I know there are no types in bash.

View 11 Replies View Related

Programming :: Nontrivial String Replacement With Bash On-board Means?

Jan 9, 2011

My simple bash-script replaces --> by the HTML-entity for the right arrow. To be precise, it replaces --*> by → Until now, I used sed, for example:

Code: $ flight='AMS --> JFK'
$ echo "$flight" | sed -e 's/ --*> / → /g'

AMS → JFK With sed, -* matches zero or more dashes, because for sed the * is the Kleene Star matching zero or more instances of the previous element. So with sed, --*> matches exactly what I want:

Code:

->
-->
--->
---->

Because sed seems oversized for that task, I played around to accomplish the same with on-board means of bash without using sed. On first thought, this line looks like doing the same but it isn't:

Code: $ flight='AMS --> JFK'
$ echo "${flight// --*> / → }"

AMS → JFK As I recently learnt in this forum, this * isn't the Kleene Star. It is a multi-character wildcard matching any zero or more consecutive characters. So here, --*> matches:

Code:

->
-->
--->
---->
-<>
->>

-abc> And if you continue your flight to SEA, then the result is totally wrong because the * matches greedily:

Code: $ flight='AMS --> JFK --> SEA' $ echo "${flight// --*> / → }" AMS → SEA

The sed line above would produce the correct result and would match the dashes correctly.

View 3 Replies View Related

Programming :: Find String In Text File (bash Script)

Apr 17, 2011

write such script (bash script). I have some text file with name filename.txt I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable.

For example. File: PHP Code: PHP Code:
Start 15022011 Eng 12-3-42
SN1232324422 11 test-string-first
SN322211 securities
HH keyword-string:123456321-net mark (11-22) 

[Code].....

View 1 Replies View Related

Programming :: Bash Regexp String Compare Stopped Working?

Oct 20, 2010

Have a bash script which contains a line like this:

if [[ ${array[${last}]} =~ "screenpc.PRODUCTION.*" ]]

which WORKED as expected in bash 4.0.33 and now fails in 4.1.2

Instrumented the script to print the value of the left-hand side and it is exactly what is expected.

As noted above, this has been working fine until we installed Fedora 13 (kernel 2.6.33), and now it fails.

Tried setting shell 'extglob' to On with same results.

Did something change? Are there other shell/bash options that need to be set?this has the whole installation stopped!

View 10 Replies View Related

Programming :: Find A Substring/member In A String/array Using Bash?

Oct 13, 2010

This may be a basic bash array/string operation related question, but I couldn't find any direct answer. So here it goes:I have a lot of data sorted in various directories. All directories need same processing except for a special group of directories. I have a symbolic link of the script in discussion in each directory. I want the script to get the name of the current directory, check if that belongs to special group and do specific operations.So I get the name of the directory

Code:
mm=`basename `pwd``
Now the the group of directories that needs something different to be done, contains these

[code]...

View 4 Replies View Related

Programming :: Copy String A To String B And Change String B With Toupper() And Count The Chars?

Oct 22, 2010

copy string a to string b and change string b with toupper() and count the chars

View 3 Replies View Related

Programming :: Find And Replace A String In A File Using Perl Command From Bash Script?

Feb 14, 2011

I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.

perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";

But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.

View 5 Replies View Related

Ubuntu :: Bash Scripting Gives Bad Substitution

Feb 18, 2011

I'm trying to get the substring of a string in bash. Here is the code:
Code:
#! /bin/bash
LOCAL_HOSTNAME=$(hostname)
echo $LOCAL_HOSTNAME
INDEX_OF=`expr index "$LOCAL_HOSTNAME" 1`
echo $INDEX_OF
SERVER_HOSTNAME=${LOCAL_HOSTNAME:0:INDEX_OF}
echo $SERVER_HOSTNAME

It's supposed to get the current hostname, assign it to variable LOCAL_HOSTNAME, get the first occurrence of "1" from hostname and assign value to INDEX_OF, the get the substring from variable LOCAL_HOSTNAME (starting at index 0 through INDEX_OF) and asign it to SERVER_HOSTNAME. No matter how much I've tried it keeps throwing Bad substitution error at the substring. I've searched and it says it has to be bash... but it is bash, both the sh script and the running shell. The LOCAL_HOSTNAME and INDEX_OF variables are ok.

Here is the output:
I've also tried to get the substring without the INDEX_OF but it gives the same error: SERVER_HOSTNAME=${LOCAL_HOSTNAME:0}
Code:
host1
5
test.sh: 7: Bad substitution

View 2 Replies View Related

Debian :: /bin/dash: Bad Substitution Shown Repeatedly Until Kill Process

Mar 16, 2011

if i run /bin/dash at the command prompt I get the message /bin/dash: Bad substitution shown repeatedly until I kill the process

View 14 Replies View Related

General :: Function Having Background Process Inside Command Substitution

Oct 5, 2010

The first call to "somefunction" works as expected. The function prints "endfunction" and a process in background sleeps 30 seconds. In the second call I thought it should work in the same way, but the script sleeps 30 seconds before it prints "endfunction".Does someone know the reason of this behavior? Is there another way to do a command substitution of a function that has a background process without have to waiting for that process?

View 2 Replies View Related

General :: Determine On System Where Process Substitution Creates FIFO Files?

Aug 16, 2011

I'm writing a C++ application and need to work with process substitution in the Bash shell. I'm trying to find a way to validate the paths passed as arguments to my program, some of which point to FIFO files created by process substitution.

Is there a shell (or C++) way that I can check if the system creates these files in /dev/fd or if they are created somewhere else?

View 2 Replies View Related

General :: Mkdir In Bash Script - Command Substitution

Jun 26, 2010

I was to set up a cronjob that sends its output to a logfile, i want that log file to be unique. the easiest way to set this up would be to make the directory in the script, then output the command to that directory, they call that directory via is full path in cron (because cron only uses full path names.

This does not work

keep in mind the command "/bin/mkdir -p /tmp/pw_log/`date +20%y%m%d_%H%M%S`.log" works fine on the command line - but once I put it in the shell, it does not work.

View 3 Replies View Related

Programming :: Scripting, Perl Or Bash; Run A Background Process, Get Pid?

Apr 1, 2010

pretty simple. how would you background a process from a script and get its process id at the same time?

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved