w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How can one create and then use an alias in a function of a sourced Bash script?
Note that aliases will have limited functionality for scripting. From the Advanced Bash Scripting Guide: In a script, aliases have very limited usefulness. It would be nice if aliases could assume some of the functionality of the C preprocessor, such as macro expansion, but unfortunately Bash does not expand arguments within the alias body. [2] Moreover, a script fails to expand an alias itself within "compound constructs," such as if/then statements, loops, and functions. An added limitation is that an alias will not expand recursively. Almost invariably, whatever we would like an alias to do could be accomplished much more effectively with a function. I would use a variable for this: myFunction(){ zappo="echo" $zappo "foo bar" } Or even a wrapper function: zappo() {

Categories : Bash

Run bash script as if I it was executed from a different directory
you could change the working directory before you execute each script, or redirect the output to the directory you want: cd /experiments/exp1/ sh /experiments/exp1/script1.sh >report1.txt or sh /experiments/exp1/script1.sh > /experiments/exp1/report1.txt

Categories : Linux

MySQL directly gives results, though none through script
print_r($array, true); is your problem $zapytanie = "SELECT IN FROM all_orders WHERE ID IN(2,3,5...) AND status='sent' ORDER BY ID ASC"; $array = array(); $result = mysqli_query($con,$zapytanie); while($row = mysqli_fetch_array($result)) { $array[] = $row['ID']; } print_r($array);

Categories : PHP

results of Awk command different when executed from a tty versus a script
Because command substitution (using `backquotes`) treats backquotes specially. You will have to quote every again. Or use $() command substitution, as suggested elsewhere. This should work better: endlines=`cat ${src_path}/${bakfile} |awk '/\\\./ {print NR;}'`

Categories : Linux

Query runs fine when executed on DB directly , but when executed using php it fails
The problem is you can't use INTO OUTFILE statement in PHP. MySQL docs says: The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. If you want to create the resulting file on some other host than the server host, you normally cannot use SELECT ... INTO OUTFILE since there is no way to write a path to the file relative to the server host's file system. I think, their suggestion below can help you. However, if the MySQL client software is installed on the remote machine, you can instead use a client command such as mysql -e "SELECT ..." > file_name to generate the file on the client host. If not, maybe there will be other way, but I'm sure you need to dig into that way.

Categories : PHP

nmap slow when called from bash script
In the script you're calling nmap -sn 168.1.1.0-255 rather than nmap -sn 192.168.1.0-255. 192.168.* is a private subnet which is understandably quicker to scan than 168.1.1.*, a public IP address range out on the Internet.

Categories : Bash

Cloning git in bash script called from php webpage
So to pack up my comments in an answer: The shell script is now run as apache, as git uses ssh, corresponding config files are needed. Which were created in /var/www; apaches home directory. Apache did not have write permissions in /var/www thus could not create these files. To resolve, create the /var/www/.ssh directory yourself and give www-data (or whatever user apache runs under in your system) write access to that folder. Next, github requires you to authorize ssh keys. It is safer to create a new one for apache in the newly created /var/www/.ssh directory and add this key to your github keychain.

Categories : PHP

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

How to exit powershell from a sourced script?
You can use this instead: [Environment]::Exit(0) But be warned - it will exit the PowerShell console completely. That's a pretty big hammer. :-) A better way is to use a trap handler in outer.ps1 e.g.: trap { exit 0 } And in inner.ps1 do a throw e.g.: throw "Inner.ps1 done!"

Categories : Powershell

Processing output of python file called inside a bash script
If you mean the output of python, you should test it with $() instead #!/bin/bash if test "$(python /var/lib/scripts/Hudson.py result)" = "Success" then Run next command else Exit the script fi And it's actually better with [[ ]] #!/bin/bash if [[ "$(python /var/lib/scripts/Hudson.py result)" == "Success" ]] then Run next command else Exit the script fi If you mean the exit code: #!/bin/bash if python /var/lib/scripts/Hudson.py result then Run next command else Exit the script fi

Categories : Linux

How to detect whether a script is dot-sourced, or loaded as part of a module using powershell v2+?
This doesn't directly answer your question but may help you achieve your goal. Use the -Function or -Cmdlet parameters of import-module to selectively import parts of the module. http://technet.microsoft.com/en-us/library/hh849725.aspx -Function<String[]> Imports only the specified functions from the module into the current session. Enter a list of functions. Wildcard characters are permitted. Some modules automatically export selected functions into your session when you import the module. This parameter lets you select from among the exported functions. -Cmdlet<String[]> Imports only the specified cmdlets from the module into the current session. Enter a list of cmdlets. Wildcard characters are permitted. Some modules automatically export selected

Categories : Powershell

Android Activity onDestroy() is not always called and if called only part of the code is executed
Take a look at this: Activity OnDestroy never called? And this: http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29 Basically, there's never a guarantee that onDestroy() will be called, and in some cases processes such as your app will be killed directly, bypassing the method call anyway.

Categories : Android

bash: getopts called in function not picking up flags
getopts acts on the parameters passed into your function, so in your case you have to call the upd() function with "$@", to pass all the command line parameters into your function. eg: test() { while getopts "o" opt; do case $opt in o) echo o ;; ?) echo "Invalid option: -$OPTARG" >&2 ;; esac done } test # this wont work as $1, $2, ... are not set test $@ # this will work as you pass along the command line parameters Edit I overlooked the .bashrc part, if I source the example above, into my running shell, then test -o works as expected.

Categories : Bash

HttpGet works fine if called directly but issues a 400 response if called from Android Activity
OK Folks check this out Keep it very simple - it is not the script that is bad, No sir.. Your Web.Config may have a HttP conflict that 400 error is asking to load a webpage that is not responding. So you must check a few minor details minor bcs you know the script is good so now you have to check your setting and how the computer and browser responds... To Resolve try this First Clear your DNS Cache and delete cookies 1. Reset your web browser then go to script replace website.com with actual web url. 2. for service, replace webHttpBinding with basicHttpBinding 3. Make sure your header lines are not long remember keep it simple For further assistance email me Frankieperez@yahoo.com

Categories : Java

header is executed directly
There are a few different things wrong in your code. First, the header calls should be the first thing you output. You don't do that. You have unbuffered prints before it. From the (very good) PHP documentation: Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. Second, even if you would have used buffered output, the Javascript would never execute as the body is not evaluated when there is a Location header. Third, using mysql_error to find out if a certain r

Categories : PHP

Function runs on CLI but not from bash script
This is most likely caused because of too strong quoting. This error line bash: /bin/echo 'hello'; bash -l: No such file or directory shows that bash does not try to execute the command /bin/echo with the argument 'hello' followed by the command bash -l. Instead bash is trying to execute the command /bin/echo 'hello'; bash -l. Compare: $ ssh localhost -t "/bin/echo 'foo'; bash -l" foo $ logout # this is the new shell Connection to localhost closed. and: $ ssh localhost -t '"/bin/echo 'foo'; bash -l"' bash: /bin/echo foo; bash -l: No such file or directory Connection to localhost closed. The solution to this problem usually involves eval, but I cannot tell for sure unless I see more code from you.

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

php function script not getting called in joomla
where you defind $mosConfig_live_site value try to read http://docs.joomla.org/Creating_a_simple_module also try to give full url/path on your each included files like:- JURI::root().'css/joomla.css';

Categories : PHP

function not being called first time script runs
First of all, I don't see the advantage of declaring the label variable with global scope in the context of the code you've shared. Since you're returning a label from the getLabel function then I think you should just declare var label; at the top of the getLabel function and return the value of that local variable from the function. Second, the only way I can see that "undefined" would be returned from getLabel is if f.attributes.label is undefined. I would try a code block such as: } else { // is not cluster if (f.attributes.label != null && typeof(f.attributes.label != "undefined") { // if (f.attributes.label) { // alternate simpler if statement label= " " + f.attributes.label; } else { label = " "; } }

Categories : Javascript

Generate all possible combinations of a function call using Bash script
Maybe there is a shorter version. I add pure bash soltution: #!/bin/bash # extract arguments to $arg fnc=" - abc(i,j,k)" pre=${fnc%%(*} post=${fnc##*)} arg=${fnc#*(} arg=${arg%)*} # put arguments to arr array IFS=, read -a arr <<<"$arg" num=${#arr[@]} # Generate all output lines for((i=0; i<1<<num; ++i));{ tmp=() for ((j=0; j<num; ++j));{ if ((i & (1<<j))); then tmp[j]="" else tmp[j]=${arr[j]} fi } printf -v tmp ,%s "${tmp[@]}" echo "$pre("${tmp:1}")$post" } Output: - abc(i,j,k) - abc(,j,k) - abc(i,,k) - abc(,,k) - abc(i,j,) - abc(,j,) - abc(i,,) - abc(,,) The script uses variable fnc as input. The it separated to three parts: pre, args, post. The args are arrayized. Then it produces the output for each possible variatio

Categories : Bash

How to write the results of a batch file called in a Python script to a file
Why are you calling list2cmdline? This doesn't actually call the subprocess. Use subprocess.check_output instead: import os output = [] for _, _, files in os.walk(directory): for f in files: fullpath = os.path.join(directory, os.path.basename(f)) output.append(subprocess.check_output([fullpath])) print ' '.join(output)

Categories : Python

jQuery function is not called when script src is added to head
Your include jQuery like three times in this code. i'm not sure if thats the problem but it ain't the solution // jquery from jquery.com <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <!-- jQuery (required) --> // jQuery from google <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="../js/jquery.min.js"></script>')</script> // both of these are expendable this might cause a conflict since the last one to be included is an older version of the library. you only need only inclusion. I'm assuming your using migrate because you have older jQue

Categories : PHP

Preventing AJAX-called PHP-Script to execute a function
You could simply, check within the PHP file, who or what is requesting the PHP file! // If the request came from AJAX then do this if ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest") { // Perform Ajax related stuff } else { // Perform non-Ajax related stuff } Though, take in mind that headers can always be faked!

Categories : PHP

Function failure - shell script converted from Bash to Korn
The function declaration syntax in ksh either uses the function keyword or the parentheses, but not both. Leave out either the parentheses or the function keyword and it should work.

Categories : Bash

Bash function - return parent script file path
As soon as the parent script starts export "`pwd`/$0" or so, into an env variable, say ORIG_SCRIPT, then in the function just use ORIG_SCRIPT. You need to do this as soon as the script starts because $0 may be relative to the PWD and if you later change PWD before you need the value of ORIG_SCRIPT, it gets unnecessarily complicated. Update: Since you know the pid by $$, you may get something from /proc/<PID>/cmdline but I don't know how exactly this one works right now.

Categories : Bash

Bash script to wait for gnome-terminal to finish before continuing script, only works for first instance of script
#!/bin/bash date bash -c "sleep 7" & bash -c "sleep 5" & wait date As you can see while running this script, both sleep commands will run in parallel, but main thread stalls, while they are running. Sat. Jule 27 01:11:49 2013 Sat. Jule 27 01:11:56 2013 Replace sleep 7 with expect launchneuron.exp and sleep 5 with expect launchmpj.exp and add your plot commands after calling "wait": echo "Simulation Complete" ...(your code to plot results)

Categories : Bash

Two bash jobs executed at the same time
See here (Google is your friend). You can make the processes background tasks with the & sign, then use wait to have the parent process wait for its children.

Categories : Python

Force bash executed in a pipe to enable echoing
So, there is a way, like an option in the bash parameters, to force it adding the input to the output? Yes: you can use the -v command-line option ("Print shell input lines as they are read.").

Categories : Python

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

Invoke python script from another python script and set execution directory of the executed script
You could use cwd parameter, to run scriptB in its directory: import os from subprocess import check_call check_call([scriptB], cwd=os.path.dirname(scriptB))

Categories : Python

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

bash: propagating exit code of command executed in alias
It's better that you just use functions over aliases: cda() { cd /a exit_code=$? echo "STATUS: $exit_code" return "$exit_code" # optional } cdb() { cd /b exit_code=$? echo "STATUS: $exit_code" return "$exit_code" # optional } As for the alias you could try adding a test in the end: alias cda='cd /a; exit_code=$?; echo "STATUS: $exit_code"; [[ exit_code -eq 0 ]]'; alias cdb='cd /b'

Categories : Bash

executing within java a commandline bash command with no output is not executed like
If there is an error it will to go to ErrorStream , you need to attach that one also: BufferedReader bre = new BufferedReader (new InputStreamReader(p.getErrorStream()));

Categories : Java

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

'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

Different results when Matlab is executed by Windows cmd
In the Windows cmd version, you are calling it with two character arguments ('2') because you forgot the parenthesis. The correct version would be: matlab -sd myCurrentDirectory -r "testmath(2,2)" -nodesktop -nosplash Reproduce the "odd" result on the MATLAB command prompt: >> [x, y] = testmath 2 2 x = 2500 y = 1 >> [x, y] = testmath(2,2) x = 4 y = 1 The outcome is 2500, because the ASCII code for the character '2' is 50. MATLAB uses this number when applying the multiplication operator to one or two characters. This is called function/command duality; arguments passed without parenthesis are interpreted as strings. Same as >> disp hello hello >> disp('hello') hello or >> load myFile.dat >> load('myFile.dat') it can

Categories : Matlab

Backbone: how to test preventDefault to be called without testing directly the callback
So you want to test that preventDefault is called when a click event is generated, correct? Couldn't you do something like (in JavaScript. I'll leave the CoffeeScript as an exercise ;)): var preventDefaultSpy; before(function() { preventDefaultSpy = sinon.spy(Event.prototype, 'preventDefault'); }); after(function() { preventDefaultSpy.restore(); }); it('should call "preventDefault"', function() { myView.$('.save').click(); expect(preventDefaultSpy.callCount).to.equal(1); }); You might want to call preventDefaultSpy.reset() just before creating the click event so the call count is not affected by other things going on. I haven't tested it, but I believe it would work. edit: in other words, since my answer is not that different from a part of your question: I think your firs

Categories : Testing

MySQL Procedure: substring_index throwing exception from special characters (executed in bash)
Your question is really too board, but here is an example of what I mean a script file: #!/bin/bash case $# in 1 ) inFile=$1 ;; * ) echo "usage: myLoader infile"; exit 1 ;; esac awk 'BEGIN { FS=" "'; OFS="|" } { sub(/badChars/, "", $0); sub(/otherBads/, "", $0) ; # .... as many as needed # but be careful, easy to delete stuff that with too broad a brush. print $1, $2, $5, $4, $9 }' $inFile > $inFile.psv bcp -in -f ${formatFile:-formatFile} $inFile.psv Note how awk makes it very easy, by repeating sub(...) commands to remove any "bad chars" you may have in your source data AND to reorganize the order of the columns in your data. Each $n is the value in numbered column on a line, so $1, $2, $5 skips fields $3 and $4, for example. Th

Categories : Mysql

Entity Framework 5 Guid comparison results in no SQL being executed
Try the following // Create a sample item var itemType = new Guid("27733204-C1E6-4F93-BEAD-63C2C8EBC299"); // Create a holder for the value of ItemType. // EF will not be able to translate itemType.ToString() // to SQL if you try to call it directly. var itemTypeValue = itemType.ToString(); // Execute your query // I placed ToList() to force the // execution. You can use anything // that will cause the query to enumerate. var items from myDBContext.Items.Where(x => x.itemType == itemTypeValue).ToList();

Categories : C#



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