w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
What does &hellip mean/do(from Java Generics FAQ)?
That's an HTML entity; it stands for Horizontal Ellipsis. It looks like this: … (One symbol; not three separate dots) That means that their HTML is broken.

Categories : Java

What is the difference between ${var}, "$var", and "${var}" in the Bash shell?
Well, I know that encapsulation of a variable helps you to work with something like: ${groups%example} or syntax like that, where you want to do something with your variable before returning the value. Now, if you see your code, all the magic is inside ${groups[@]} the magic is in there because you can't write just: $groups[@] You're putting your variable inside the {} because you want to use special characters [] and @. You can't name or call your variable just: @ or something[] because this are reserved characters for other operations and names.

Categories : Bash

difference between bash and sh -c option
The syntax <(...) is only supported by BASH. For any POSIX shell, use this approach: sh -c 'tail -n 1000 -F catalina.out | if grep -qP --line-buffered ".+" ; then ...' i.e. move the stdin redirection in front of the if with a pipe. The if will pass stdin on to the grep. if tail ...| grep won't work since the if won't be able to see it's then/fi because the pipe separates processes.

Categories : Linux

Bash: difference between cat and echo
Because there is no end of line in file.txt, if you: $ od -c file.txt 0000000 f o o : b a r : b a z : q u x : 0000020 q u u x o n e : t w o : t r e 0000040 e : f o u r : f i v e : s i x : 0000060 s e v e n a l p h a : b e t a 0000100 : g a m m a : d e l t a : e p s 0000120 i l o n : z e t a : e t a : t e 0000140 t a : i o t a : k a p p a : l a 0000160 m b d a : m u t h e q u i c 0000200 k b r o w n f o x j u m p 0000220 s o v e r t h e l a z y 0000240 d

Categories : Bash

Understanding the difference between = and =~ operators in bash [[ ]]
[[ $a =~ $b ]] is a regular expression match. In this syntax, * matches 0-n instances of the immediately preceding character or pattern. [[ $a = $b ]] is a glob-style pattern match. In this syntax, * matches 0-n characters of any type. Note that it is important that regular expressions in bash be stored in variables. That is: re='[0-9]{1,2}ab' [[ $foo =~ $re ]] may actually be different from [[ $foo =~ [0-9]{1,2}ab ]] ...depending on which version of bash you're running. Always using a variable will prevent this from causing problems. Note that these are both different from re='[0-9]{1,2}ab' [[ $foo =~ "$re" ]] ## <- LITERAL SUBSTRING MATCH _NOT_ REGULAR EXPRESSION MATCH ...in which case the quoting makes the contents of $re literal, ie. not treated like a regular expression

Categories : Regex

Difference between bash-script and cocoa code with OpenSSL
It was error in Cocoa-snippet. There is good code: const char* buffer = "RF001"; uint8_t md[SHA_DIGEST_LENGTH]; SHA1((uint8_t*)buffer, strlen(buffer), md); NSData* data = [NSData dataWithBytes:md length:SHA_DIGEST_LENGTH]; NSLog([data description], nil);

Categories : Objective C

Another split file in bash - based on difference between rows of column x
I suggest small modifications to your current script: awk 'BEGIN { fn=0; f=sprintf("file_no%02d.txt",fn++); print "Creating " f } NR==1 { next } NR==2 { delim=$2 } $2 - delim < 0 { f=sprintf("file_no%02d.txt",fn++); print "Creating " f } { print $0 > f; delim = $2 }' infile First, create the first file name just before starting the processing. Second, in last condition save the value of current line to compare with the value of next line. Third, instead the comparison with zero, do the substraction between previous value and current one to check if result is less than zero. It yields: ==> file_no00.txt <== 6 0 0 3 5.16551 12.1099 1 10.2288 19.4769 6 20.0249 30.6543 3 30.0499 40.382 1 59.9363 53.2281 2 74.9415 57.1477 2 89.9462 61.3308 6

Categories : Bash

difference between executing script using bash file.sh and ./file.sh
If "file.sh" is not executable then ./file.sh will not work but bash file.sh will. If "file.sh" does not start with the line #!/bin/bash (or another path to a valid bash interpreter) then ./file.sh will not work but bash file.sh will. Basically, in order for a script to look like an executable file it must: Have execute permission. Start with the line #!/path/to/interpreter.

Categories : Bash

What is the difference between variable post-increment/decrement and pre-increment/decrement in bash?
Quoting from Increment and decrement operators: In languages that support both versions of the operators, the pre-increment and pre-decrement operators increment (or decrement) their operand by 1, and the value of the expression is the resulting incremented (or decremented) value. In contrast, the post-increment and post-decrement operators increase (or decrease) the value of their operand by 1, but the value of the expression is the operand's original value prior to the increment (or decrement) operation. So, you'll find: $ x=5; echo $(( x++ / 2 )) 2 $ echo ${x} // The effect of post-increment is visible here 3

Categories : Bash

Why does the child of an eval call from bash get orphaned once the parent bash script dies?
This is normal and expected. You sent a signal (presumably SIGTERM) to parent-script and it died, but no signal was sent to another-script. It keeps on running. This is different than what happens when the parent-script job is running interactively on a terminal and you type ^C (or ^Z). In that case, a SIGINT signal is automatically sent to the whole foreground process group. Since another-script is un the same process group as parent-script (by default), they both get the signal and they both die. If you want another-script to die automatically when its parent dies in any other context than when it's a job running in a terminal with job control, you have a few options. parent-script can trap the SIGTERM signal. In the signal handler, it kills its child, and then exits itself. This, o

Categories : Linux

Redirecting standard input in Bash implies that Bash executes a default action?
exec 6<&0 0</tmp/lines.txt; exec 0<&6 6<&- Turns out that bash still executes what remains in the command specified or script before it reads input for commands again that's why your file /tmp/lines.txt is not read since exec 0<&6 6<&- is run before it. Please refer back to the previous solution if you want to execute commands in /tmp/lines.txt before exec 0<&6- is executed. Also it might have not been obvious but you could use . or source to achieve same output: . /tmp/lines.txt source /tmp/lines.txt

Categories : Bash

execute user inputed Windows (or bash) commands from batch (or bash) file?
Do you need a full bash prompt? Or would something like this be enough? #!/bin/bash echo -n "Enter cmd: " read COMMAND echo ${COMMAND} | bash Also, in a script, you can just execute bash and get a full prompt in the current environment.

Categories : Bash

BASH: how to define an array as environment variable before calling a bash script
Incredibility weird.... I have never seen that before. It looks like the array is not passed to the subshell. One way around this is to source the script instead of executing it: declare -a MYARR=( 1 2 ); . ./myscript.sh

Categories : Arrays

Capture output of a bash command, parse it and store into different bash variables
You can use awk and bash arrays: arr=( $(awk -F ':' '$1 == "inet addr"{sub(/ .*/, "", $2); print $2}' < <(ifconfig)) ) Then you can do: read IPETH0 IPLO <<< ${arr[@]}

Categories : Linux

Pass a full bash script line to another bash function to execute
optout is a command like any other, and so must be preceded by any local modifications to the environment. The command that optout runs will inherit that environment. CC=${BUILD_TOOL_CC} optout ./configure ${ZLIB_CONFIGURE_OPT} --prefix=${CURR_DIR}/${INSTALL_DIR} By the way, this is just one of the problems you are likely to encounter with your optout function. You cannot run arbitrary command lines in that fashion, only a simple command followed by zero or more arguments (and I would expect there are some exceptions to even that restricted set, as well).

Categories : Linux

BASH | Adding elements in all files of a specific directory bash
This can make it: for file in /your/dir/* do echo "<end>" >> "$file" done In case you have some dirs inside, you may get the error bash: XX: Is a directory. To avoid seeing them, you can add 2>/dev/null to the end of the echo command: echo "<end>" >> "$file" 2>/dev/null Or even better (thanks Barmar), check if they are files: [ -f "$file" ] && echo "<end>" >> "$file" Which is a short way of doing an if-condition: if [ -f "$file" ]; then echo "<end>" >> "$file" fi

Categories : Bash

Cygwin Installation: Package: bash; bash.sh exit code 1
The /dev directory is missing and cygwin fakes it, which makes it read-only. The following code: cd /etc/postinstall/ ./000-cygwin-post-install.sh.done ./bash.sh ... solved that error for me.

Categories : Bash

Redirecting standard input in Bash implies that Bash exits
That makes bash read commands from /tmp/lines.txt redirecting its input in the process. There would no longer be any input to process after all those commands in the file so the shell just exits after it, just like executing a shell script. If you want to not let bash exit after the commands in /tmp/lines.txt were processed, make sure that you could put back its input like: exec 6<&0 < <(cat /tmp/lines.txt; echo; echo "exec <&6";) Which send both inputs of /tmp/lines.txt as commands and also exec <&6 that would put back input from &6 encapsulated by process substition. And a cleaner approach: exec 6<&0 < <(cat /tmp/lines.txt; echo; echo "exec <&- <&6 6<&-";) Or simply: exec 6<&0 < <(cat /tmp/lines.txt; e

Categories : Bash

'Globalize' Bash functions inside of a bash script
You can use this command in your startup.bash: source lib.bash the source command runs the file in the current shell environment, unlike using bash lib.bash (or . lib.bash) which creates a new, separate environment for that script (and only that script) and is why the function is not carried over. (source)

Categories : Linux

Can One Bash Script Launch Multiple Other Bash Scripts?
Run them in the background, just like you would in an interactive shell. command1 & command2 & command3 & wait # Wait for all background commands to finish The commands can be just about anything, not just other bash scripts.

Categories : Linux

escaping bash 'test' keywork in a bash script
test is a Bash builtin command, not a keyword or reserved word. This means Bash will only interpret it if it is the first token in a command, like test blah In python manage.py test Bash will just pass it as a parameter to python (that is, it will execute python with two parameters, manage.py and test); you don't need to escape it. In general, Bash doesn't have reserved words in the sense of C-like languages. The only things you need to escape are whitespace (which Bash uses to separate params), and certain symbols including $(&|; which Bash uses for its variables and command separators.

Categories : Bash

BASH | How to get the number of fields of one line in bash (using cut ?)
You can say: $ echo "field1;field2;field3;field4;" | grep -o ";" | wc -l 4 Alternatively, $ tr -dc ';' <<< "field1;field2;field3;field4;" | wc -c 4 EDIT: In order to loop over the fields, you can say: $ IFS=';' read -ra field <<< "field1;field2;field3;field4;" $ for i in "${field[@]}"; do echo $i; done field1 field2 field3 field4

Categories : Linux

execl("/bin/bash","bash","-l","-c","env",NULL), what's wrong?
Edit note: This is a full rewrite of the original example code, since the OP posted the code and I realized it causes bash to block on standard output instead of input as I originally thought. The reason is bash output is redirected to a pipe, with nothing reading from the pipe until the child exits. Before you execl(), reopen STDIN_FILENO from /dev/null, and STDERR_FILENO to /dev/null. When STDOUT_FILENO (standard output) is redirected to a pipe, you cannot just wait() for the child to exit: you must actively read from the pipe while the child process runs. Consider this example program. It takes one command-line parameter, the user name. (Without any parameters or just -h or --help it outputs short usage information.) It obtains the struct passwd corresponding to that user name, creat

Categories : C

Run a bash including a variable in the "bash XXX.sh" command
You can take advantage of shell parameter expansion to smoothly read variables from the environment of the parent process, if it's that what you want to achieve. Look at the following script named test.sh: #!/bin/bash VARIABLE=${VARIABLE:="default value"} echo $VARIABLE If you start it with the line $ ./test.sh it outputs default value But if you invoke test.sh with the line $ VARIABLE="custom Value" ./test.sh it outputs custom value But make sure that the variable assignment is at the beginning of the line. Otherwise it is passed to test.sh as command line argument. The used form of parameter expansion ${parameter:=word} is described in the bash reference manual as: If parameter is unset or null, the expansion of word is assigned to parameter. The value of param

Categories : Bash

Why does adding extra check in loop make big difference on some machines, and small difference on others?
One big difference between CPUs is the pipeline optimization The CPU can execute in parallel several instructions until reaches a conditional branch. From this point instead of waiting until all the instructions are executed, the CPU can continue with a branch in parallel until the condition is available and ready to be evaluated. If the assumption was correct, then we have a gain. Otherwise the CPU will go with the other branch. So the tricky part for a CPU is to find the best assumptions and to execute as many instructions in parallel as possible.

Categories : C++

What do blue-difference and red-difference chroma components mean in YCbCr color space?
The Cb and Cr components of the YCbCr, or YCC, color space are not immediately physically intuitive. Cb and Cr respectively represent the blue-difference and red-difference chroma signals as you noted. Chromaticity represents the perceptual deviation from the neutral, i.e. grayscale, so the greater the deviation, the higher the intensity of chroma. An image with low chroma is less colorful, and conversely. And so, Cb and Cr are one representation of changes in blue and red "colorfulness", respectively. Each colorspace has different advantages, mostly related to how sensitive channels to changes. For example, YCbCR is widely popular for its compressibility in the Cb and Cr channels by subsampling. Or, when doing things in computer vision like image matching using color-based methods, it is

Categories : Image

Find difference between rows of same column (difference between time data)
Try: DATEDIFF (mi, CAST(mc.login AS DATETIME), CAST(mp.login AS DATETIME)) as diff This will get difference in minutes SQLFiddle DEMO

Categories : Asp Net

Postgres sql 8.4 Use of Time Difference and Date Difference Separately
Here is the SQLFiddel Demo Below is the query which you can try select EmpHrs.ID_EMP, EmpHrs.Name, ( (EmpHrs.NOOFHRS*20)- (EmpHrs.NOOFHRS* JuneSuspension.MONTHSUSPENSION) ) as "June-2013", ( (EmpHrs.NOOFHRS*20)- (EmpHrs.NOOFHRS* JulySuspension.MONTHSUSPENSION) ) as "July-2013" from ( select ID_EMP,NAME, Extract(Hours from time_end-time_initial)+ Extract(Minutes from time_end-time_initial)/60 as NoOfHrs from schedule ) EmpHrs Left join (select ID_EMP,to_char(to_timestamp (Extract(Month from suspension_initial)::text, 'MM'),'Mon') as MonthIni,(suspension_end::date - suspension_initial::date)+1 MonthSuspension from suspension where Extract(Month from suspension_initial) = 6) JuneSusp

Categories : SQL

A difference-in-difference boxplot-like plot in Matlab
How about something along the lines of: x = rand(2, 1); % ? maybe just leave out? y = rand(2, 1); % [mean(Apre), mean(Apost)] e = rand(2, 1)*.2; % ? is this maybe [std(Apre), std(Apost)] errorbar(x, y, e, 'o-'); % You can leave off the x here if you don't need it hold all %Now repeat for B x = rand(2, 1); y = rand(2, 1); e = rand(2, 1)*.2; errorbar(x, y, e, '^-'); legend({'First series', 'Second Series'})

Categories : Matlab

BASH - If $TIME between 8am and 1pm do.., esle do.. Specifying time variables and if statements in BASH
In this case, you just need to look at the hour. Also, bash has syntax to specify the radix of a number, so you don't have to worry about 08 and 09 being invalid octal numbers: H=$(date +%H) if (( 8 <= 10#$H && 10#$H < 13 )); then echo between 8 and 1 elif (( 13 <= 10#$H && 10#$H < 23 )); then echo between 1 and 11 else echo go to bed fi "10#$H" is the contents of the variable, in base 10.

Categories : Mysql

Outputting difference in two pandas dataframes side by side - highlighting the difference
If your two dataframes have the same ids in them, then finding out what changed is actually pretty easy. Just doing frame1 != frame2 will give you a boolean DataFrame where each True is data that has changed. From that, you could easily get the index of each changed row by doing changedids = frame1.index[np.any(frame1 != frame2,axis=1)].

Categories : Python

bash script to write content into file. File content requires bash variables. How to do that?
You're actually deliberately turning off parameter subsitution by enclosing 'ENDFILECONTENT' in quotes. See this excerpt from example 19-7 of the advanced Bash scripting guide on Heredocs, slightly reformatted: # No parameter substitution when the "limit string" is quoted or escaped. # Either of the following at the head of the here document would have # the same effect. # # cat <<"Endofmessage" # cat <<Endofmessage Remove the single quotes around 'ENDFILECONTENT' and BASH will replace the variables as expected.

Categories : Bash

-bash: cordova: command not found; or -bash: phonegap: command not found
You've to add the path to the cordova bin in the bash file. /etc/profile ~/.bash_profile ~/.bash_login (if .bash_profile does not exist) ~/.profile (if .bash_login does not exist) Try to close and reopen the teminal after edited the file.

Categories : Cordova

find difference between lists and append difference to lists, but for 40 different lists - python
Sounds like you could use sets: >>> {1, 2, 3, 4, 5} & {2, 3, 4, 5, 6, 7} & {3, 4, 5} {3, 4, 5} & is the intersection operator for sets. Get a set of a list (this will remove duplicate elements with set(mylist). Edit: In the light of your comments, it seems what you need is some sort of union (the union operator being |), not an intersection. Here is a function that does what you wanted in your comment for 2 lists of lists: def function(first, second): first_set = {tuple(i) for i in first} second_set = {tuple(i) for i in second} return (first_set | {(i[0], 0) for i in second_set}, second_set | {(i[0], 0) for i in first_set}) >>> a = [(1,60),(3,90)] >>> b = [(2,30),(4,50)] >>> x, y = function(a, b) >>> pri

Categories : Python

What does "-ne" mean in bash?
"not equal" So in this case, $RESULT is tested to not be equal to zero. However, the test is done numerically, not alphabetically: n1 -ne n2 True if the integers n1 and n2 are not algebraically equal. compared to: s1 != s2 True if the strings s1 and s2 are not identical.

Categories : Bash

Is there a better way to do this? BASH
You can try piping a function to xargs: showCommands() { for xe in ${XECOMMANDS[@]}; do xe=$(echo ${xe#*-}) ; xe=$(echo ${xe%.*}) echo "$xe" done } showCommands | xargs -l1 ssh -p 10551 -S /tmp/manpagemaker/ssh.connect root@192.168.1.25 t 'bash -s' < ./manpagemaker.sh I don't know the contents of XECOMMANDS, but is seems like that this code is broken with cases when filenames contain space characters. Here is a way to fix that: showCommands() { for xe in "${XECOMMANDS[@]}";do echo -n "$xe" echo -ne '' done } showCommands | xargs -0 -l1 ssh -p 10551 -S /tmp/manpagemaker/ssh.connect root@192.168.1.25 t 'bash -s' < ./manpagemaker.sh -l1 means that xargs will read the pipe input line by line. Since filenames can't contain a null ch

Categories : Linux

Sed replace ">" to "/>" bash
You should escape the slash character if you use it a separator: sed 's/>//>/g' Or use another character e.g.: sed 's_>_/>_g' Note that this will replace all matches in the file, not just the last one If you want to match only > not preceded by /, you can use this: sed -r 's_[^/]>_/>_g' file

Categories : Linux

Getting bash getopts to do something
$opt will only print switches e or s for you but to print passed argument you need to echo $OPTARG as well. Like this script: while getopts "e:n:t:s:h" opt do echo $opt $OPTARG done

Categories : Bash

Bash, Awk and Oracle
I would recommend you to use bash read instead of awk and create an sql file which you can later source in sqlplus. For example, the following will create an sql file: while IFS=';' read -r id fname lname; do echo "insert into UAM.USER_DEFINITION values (UPPER('${id}'),LOWER('${fname}'),UPPER('${lname}'));" done < List_employees_a.csv > sql.file For the following file: $ cat c.csv ida;abc acff;foeee idc;fiffh fhfhf fhhhg;aaa If you run the above command it will create an sql file like follows: $ cat sql.file insert into UAM.USER_DEFINITION values (UPPER('ida'),LOWER('abc acff'),UPPER('foeee')); insert into UAM.USER_DEFINITION values (UPPER('idc'),LOWER('fiffh fhfhf fhhhg'),UPPER('aaa')); Once your sqlfile is created, login to sqlplus and do: SQL > @/path/to/sc

Categories : Oracle

Is there a vim equivalent to bash's '!$'?
Using :vsp with no arguments splits the current window. Not exactly what you're asking for, but I often use % which is the current filename: :e some_file :vsp % See :help cmdline-special

Categories : Bash



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.