w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Bash expr error
This could help. With that variation you could check very input so that only numbers would be added for the sum, even if there are lines that invalid. function countHourly { local NUMBERS TOTAL=0 I readarray -t NUMBERS < <(cat "$PLACE"/*.dailycount.txt) for I in "${NUMBERS[@]}"; do [[ $I =~ ^[[:digit:]]+$ ]] && (( TOTAL += I )) done echo "Total: $TOTAL" } Or function countHourly { local NUMBERS TOTAL=0 I while read I; do [[ $I =~ ^[[:digit:]]+$ ]] && (( TOTAL += I )) done < <(cat "$PLACE"/*.dailycount.txt) echo "Total: $TOTAL" }

Categories : Linux

Using a variable in a expr regex command
Variables are not expanded inside of single quotes, try changing them to double quotes: foo=(`expr ${bar} : ".*(${baz})"`) Or you can move the variable outside of the quotes: foo=(`expr ${bar} : '.*('${baz}')'`)

Categories : Regex

How to change NSURL variable value while debugging with LLVM in XCode using expr command?
You may try explicitly casting, i.e. expr url = (NSURL *)[NSURL URLWithString:@"www.example.com"]; Because the LLDB sometimes cannot get the return type. You may face the same similar problem when using LLDB. // For example, you should specify the return type here: expr (int)[UIApplication version] // instead of expr [UIApplication version]

Categories : IOS

bash — boolean expression evaluation without condition
Instead of S=(true false), you need to create your array like this: S=(1 0) Then this if block: if (( ${S[0]} || ${S[1]} )) then echo "true" else echo "false" fi will output: true Please note that true/false are treated as literal strings "true" and "false" in BASH.

Categories : Linux

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

check a substring in a string in bash
Use double brackets, which support wildcards: if [[ $j == *string1* ]]; then Also, don't parse ls; use a glob instead: Instead of for j in `ls ` use for j in * If you wan't the match to be case-insensitive, you can set the shopt -s nocasematch option: shopt -s nocasematch if [[ $j == *string1* ]]; then

Categories : Linux

Bash indexof substring after nth character
both operations implemented with awk contents of file indexOf: echo "$1" "$2" | awk '{print index($1,$2)}' e.g. indexOf 'abcdeabcdabcaa' 'ca' 12 contents of file indexOfAfter: echo "$1" "$2" "$3" | awk '{s=substr($2,$1);posn=index(s,$3);if (posn>0) print $1+posn-1; else print 0;}'

Categories : String

bash substring regex matching wildcard
Just remove the quotes: x=helloworldfirsttime if [[ "$x" == *world* ]]; then echo matching helloworld fi Note that this isn't regex (a regex for this would look something like .*world.*). The pattern matching in bash is described here: http://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html

Categories : Regex

-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

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

setting variables inside a compound command in bash fails (command group)
I think, you miss that /bin/true returs 0 and /bin/false returns 1 $ r='res:'; { /bin/true; r+=$?; } 2>/dev/null; echo $r; res:0 And $ r='res:'; { /bin/false; r+=$?; } 2>/dev/null; echo $r; res:1

Categories : Bash

Command works in command line but gives 'no such file or directory' in bash script
Remove the quotes around line 8. Like this: ./optAlg.exe "$inputFile" 500 2>&1 > "output/$outputFile" By placing quotes around the whole line you tell bash to execute a command which is called exactly ./optAlg.exe $inputFile 500 2>&1 > output/$outputFile and of course there is no such command. In reality you want to run ./optAlg.exe with parameters. Do not forget to place quotes around the variables because otherwise filenames that have whitespace characters are going to be passed as several arguments. Please read about arguments. And you can read about common pitfalls as well.

Categories : Bash

Combining variables in Bash to form a command sent to AppleScript using the osascript command
As a general rule, don't put double-quotes in the variable, put them around the variable. In this case it's more complicated, since you have some double-quotes for bash-level quoting, and some for AppleScript-level quoting; in this case, the AppleScript-level quotes go in the variable, the bash-level quotes go around the variable: the_url=""http://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash"" the_script='tell application "Safari" to set the URL of the front document to ' osascript -e "${the_script}${the_url}" BTW, using echo to check things like this is highly misleading. echo is telling you what's in the variable, not what'll be executed when you reference the variable on a command line. The biggest difference is that echo prints its arguments afte

Categories : Osx

Handling Spaces In Substring Searches In Bash Shell Scripts
You can escape the space: $mainSubString = *blue cheese* or quote the non-wildcard portions, one example of which is $mainSubString = *'blue cheese'* Often, it is better to store the pattern in a variable, both to simplify the quoting and to make the [[...]] expression more concise. Note that you must not quote the parameter expansion, as glenn jackman points out in his comment. pattern="*blue cheese*" if [[ $mainString = *cat* || $mainSubstring = $pattern ]]; then

Categories : Bash

How to make this command open a new terminal & execute the command within it ( Exec=bash -c "tail -n 10 -f /var/log/httpd/error_log" )
To open a terminal Exec=nameOfYourTerminalApp (eg:gnome-terminal, lxterminal, xterm) Then you can run your commands in the opened terminal. Otherwise, you can create a script with some command and run it. In that case you have to put tail -n 10 -f /var/log/httpd/error_log in the script and make it executable. Then call it with a shortcut file.

Categories : Linux

Running command on substring of every file
Do not quote the wildcard expression. You can use parameter expansion to remove parts of a string: for file in sample*.txt ; do part=${file#sample} # Remove "sample" at the beginning. part=${part%.txt} # Remove ".txt" at the end. ./cmd -foo "$part".xml -bar "$file" done

Categories : Bash

Error when using scp command "bash: scp: command not found"
Issue is with remote server, can you login to the remote server and check if "scp" works probable causes: - scp is not in path - openssh client not installed correctly for more details http://www.linuxquestions.org/questions/linux-newbie-8/bash-scp-command-not-found-920513/

Categories : Misc

run command in bash and then exit without killing the command
In general, if you want to execute a command and not wait for it, you can simply use & as the delimiter rather than ; or a newline. When doing so, the pid of that process is available to the shell in the special variable !. If you want to wait for that process to complete, you can use wait. If you do not wish to wait for it, then simply omit the wait. In your case: python likebot.py & # Start command asynchronously echo $! # echo the pid of the most recent asynchronous process

Categories : Bash

Mysql substring string and attach chars such as ... to result command
You might be looking for CONCAT function in MySQL. SELECT id , CASE WHEN LENGTH(`subject`) >=100 then CONCAT(SUBSTR( `subject`, 1, 100 ),'...') ELSE `subject` END AS `subject` FROM `contents` Sample fiddle Have a look here as well.

Categories : Mysql

"Function evaluation disabled because a previous function evaluation timed out." - in vs2012
Why this is happening ? It seems this kind of bug can happen simply when you are trying to watch at some variables who have to be thread safe but sometimes this framework implementation is not perfect.... To avoid this problem : when stepping through code where variables are bound to windows or other controls, you don't show local variables or "auto" variables. Look at such things only when you are sure your variables are all safe to look at. And note that the error doesn't necessarily appear on the unsafe variables. Use the "immediate" window on safe (i.e. non-control) variables when operating in dangerous code. Data accessors should always be thread safe. But sometimes between two implementations (let's say between Sharepoint 2010 and Sharepoint 2012 or two version of the .NET f

Categories : Debugging

appfabric New-Cache command returning 'This command is not currently allowed. Changes to the cache cluster..."
I managed to fix this, and am posting it just in case for any future viewers. I had upgraded from AppFabric 1.0 (1) to AppFabric 1.1 (3). Apparently, the cache-hosts are locked to accept only from version 1, and you need to manually upgrade them to accept connections from version 3 (AppFabric 1.1) clients. This can be done by following the guide at: http://msdn.microsoft.com/en-us//library/hh343304(v=azure.10).aspx

Categories : C#

Run bash script on `cd` command
One feature of Unix shells is that they let you create shell functions, which are much like functions in other languages; they are essentially named groups of commands. For example, you can write a function named mycd that first runs cd, and then runs other commands: function mycd () { cd "$@" if ... ; then workon environment fi } (The "$@" expands to the arguments that you passed to mycd; so mycd /path/to/dir will call cd /path/to/dir.) As a special case, a shell function actually supersedes a like-named builtin command; so if you name your function cd, it will be run instead of the cd builtin whenever you run cd. In that case, in order for the function to call the builtin cd to perform the actual directory-change (instead of calling itself, causing infinite recurs

Categories : Python

Sed command in bash script
The simplest approach is to use the tr ("translate characters") utility, telling it to translate newlines to commas: tr ' ' , < input_file > output_file

Categories : Bash

Detect use of su command in bash
According to the man page for su, in /etc/login.defs you can set either SULOG_FILE file or SYSLOG_SU_ENABLE yes to log all su activity. Then you just need something like inotifywait to watch the log file for su events.

Categories : Linux

Bash command in Makefile
$(basename ...) is a make function. It cannot operate on shell variables, because they are expanded later than make commands. You can use the shells $(...) substitution, but you have to double the dollar sign, so makefile does not interpret it as a function.

Categories : Bash

Using '#' in bash command in .vimrc
Why not use the error message's suggestion and set PDF in Vimscript instead of in shell? Replace PDF=${TEMP:0: ${#TEMP}-4 } with PDF=%< or even PDF=%<.pdf to give it the proper extension.

Categories : Vim

Ant: what is the equivalent command in bash
The relative path for generated files matches the relative path for input files. Since you specified src/calculator4/Calculator.g4 as the input file, the output files will be src/calculator4/*.java. Change directories so the working directory is the same folder where Calculator.g4 is. Remove the -lib src/calculator4 argument. Change the -o argument to -o ../../gen/calculator4. Pass just Calculator.g4 as the final argument to the command.

Categories : Bash

In bash, what does dot command ampersand do?
The script is running in a background process, but it is a subshell, not a separately-invoked interpreter as it would be without the dot. That is to say -- the current interpreter forks and then begins running the command (sourcing the script). As such, it inherits shell variables, not just environment variables. Otherwise the new script's interpreter would be invoked via an execv() call, which would replace the current interpreter with a new one. That's usually the right thing, because it provides more flexibility -- you can't run anything but a script written for the same shell with . or source, after all, whereas starting a new interpreter means that your other script could be rewritten in Python, Perl, a compiled binary, etc without its callers needing to change. (This is part of wh

Categories : Linux

Bash command value assignment
Returns the name of the directory from which the currently running script has been started. To test it: create directory /tmp/test: mkdir /tmp/test create file 't.sh` with such content: #!/bin/bash echo $0 echo ${0%/*} give t.sh execution permission: chmod +x /tmp/test/t.sh execute it and you will see: /tmp/test/s.sh /tmp/test

Categories : Bash

bash if statement with command and sys var
Using bash globbing: if [[ $MACHTYPE = *solaris* ]]; then Using regex: if [[ $MACHTYPE =~ solaris ]]; then Pure sh solution: case $MACHTYPE in *solaris*) echo "Yes, it is solaris" ;; *) echo "No, something else" ;; esac And finally the worst solution: if /usr/bin/echo "$MACHTYPE" | grep -i 'solaris'; then Also it is /bin/echo for me, but just echo should work as well. Seems like bruteforcing doesn't work for you, so you'd better read all of these: Bash Guide: Tests and Conditionals Bash hackers: test command Bash hackers: conditional expressions

Categories : Bash

Bash error echo a command
You can write this part without the backticks: if [ "$con" -gt "4" ]; then echo -e "$ip" >> /var/log/drop_sc_ip echo -e "$ip" fi also same in this part: rm -rf $conexiuni with the backticks, it first executes what is inside the backticks and then tries to execute the output of the backticks. and change the loop: while read con ip do if [ "$con" -gt "4" ]; then echo -e "$ip" >> /var/log/drop_sc_ip echo -e "$ip" fi done < $conexiuni

Categories : Bash

bash pipestatus in backticked command?
Try to set pipefail option. It returns the last command of the pipeline that failed. One example: First I disable it: set +o pipefail Create a perl script (script.pl) to test the pipeline: #!/usr/bin/env perl use warnings; use strict; if ( @ARGV ) { die "Line1 Line2 Line3 "; } else { print "Line1 Line2 Line3 "; } Run in command-line: myvar=`perl script.pl | tail -1` echo $? "$myvar" That yields: 0 Line3 It seems correct, let see with pipefail enabled: set -o pipefail And run the command: myvar=`perl script.pl fail 2>&1 | tail -1` echo $? "$myvar" That yields: 255 Line3

Categories : Bash

BASH script, !=: command not found
That's not the way to compare it. if $OUTP != average: Should be if [[ $OUTP != average: ]] Some line seemed odd as well OUTP= uptime | awk '{print $10}' | cut -f1 -d, I think should be OUTP=$(uptime | awk '{print $10}' | cut -f1 -d,) And then $OUTP >> $Oad.lst if you want to send the value of the variable to the file, it should be then echo "$OUTP" >> "$Oad.lst" Overall I would suggest a format like this: #!/bin/bash Oad=$(date +%Y_%m_%d.%H.%M.%S) for i in {1..120}; do OUTP=$(uptime | awk '{print $10}' | cut -f1 -d,) echo "$OUTP" if [[ $OUTP != average: ]]; then echo "$OUTP" >> "$Oad.lst" sleep 60 fi done awk '{if(min==""){min=max=$1}; if($1>max) {max=$1}; if($1<min) {min=$1}; total+=$1; count+=1} END {print to

Categories : Bash

Bash Script to function as wc command
You need to build the options in the case statement and then execute wc: # Set WC_OPTS to empty string WC_OPTS=(); while getopts lwc choice do case $choice in l) WC_OPTS+='-l';; w) WC_OPTS+='-w';; c) WC_OPTS+='-c';; ?) echo wrong option. esac done # Call wc with the options shift $((OPTIND-1)) wc "${WC_OPTS[@]}" "$@"

Categories : Bash

How to Use Bash getopts Command to Get All Arguments Together
#!/bin/bash while getopts "l:f:" opts; do case $opts in l) lOn=1 ;; f) fOn=1 ;; esac done if [[ -n $lOn && -n $fOn ]]; then echo 'both l and f' elif [[ -n $lOn ]]; then echo 'just l' elif [[ -n $fOn ]]; then echo 'just f' else echo 'nothing' fi If statements give you more flexibility in situations when you want to check for other variables or do more complex stuff. This wont work in sh unless you change [[ ]] to [ ].

Categories : Bash

HomeBrew -bash: $: command not found
It looks like you copied a line from a website or other source. Generally, terminal commands are prefixed by a sample terminal prompt in documentation. For example, if you're instructed to run the ls command, you'll often see it printed as $ ls in documentation. That $ is not part of the command, it merely represents a terminal prompt. So run brew install pyqt without the $.

Categories : Osx

Create variable BASH command
A working script would look like this: # set propper default value top="" if [ -n "$2" ] then # use double quotes instead of back-tics # back-tics are for command substitution # but you need the command itself as a string top="| head -n $2" fi awk '{print $17, ">", $19;}' "$logs_folder$i" | sort -g | uniq -c | sort -r -g $top

Categories : Bash

What command means "do nothing" in a conditional in BASH?
You can probably just use the true command: if [ "$a" -ge 10 ]; then true elif [ "$a" -le 5 ]; then echo "1" else echo "2" fi An alternative, in your example case (but not necessarily everywhere) is to re-order your if/else: if [ "$a" -le 5 ]; then echo "1" elif [ "$a" -lt 10 ]; then echo "2" fi

Categories : Bash

Bash Function -> Command not found
You need to invoke the function by saying: system_info $(...) is used for command substitution.

Categories : Bash

PostgreSQL Command fom bash script
sudo -u postgres psql TestDB -c "select count(*) from config where var_name='url' The Database was missing, so you executed the command into postgres db where you probably don't have that table ;-)

Categories : Bash



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