w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
What would be the cmd.exe alternative to bash's set -e?
For Reference -e errexit Exit immediately if a simple command exits with a non-zero status, unless the command that fails is part of an until or while loop, part of an if statement, part of a && or || list, or if the command's return status is being inverted using !. http://ss64.com/bash/set.html This is unfortunately not possible with just a single command. You will have to add a check after each command you want to exit upon error. Instead of a whole separate line you can just use an or check || on the command result. command || exit /b This can also be simplified by putting it in a variable at the beginning. set "e=|| exit /b" command1 %e% command2 %e%

Categories : Batch File

Script bash shell - Making an alternative trashcan
Quick and dirty solution: if [[ -f $TRASH$PARAM ]]; then mv "$PARAM1" "$TRASH$PARAM$RANDOM$RANDOM" # file exists else mv "$PARAM1" "$TRASH$PARAM" # ok, it is fine, file does not exist fi Also please note that you have to quote every variable in your script when it is passed as a parameter. if [ ${PARAM1:0:1} = "/" ]; then must be changed to if [ "${PARAM1:0:1}" = "/" ]; then or even better if [[ ${PARAM1:0:1} = "/" ]]; then mkdir -p $(dirname $TRASH$PARAM1) to mkdir -p "$(dirname "$TRASH$PARAM1")" And so on...

Categories : Bash

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative to if, else if
What you want is a Dictionary: Dictionary<string, string> mapping = new Dictionary<string, string>(); mapping["SWGAS.COM"] = "Southwest Gas"; mapping["foo"] = "bar"; ... as many as you need, maybe read from a file ... Then just: return mapping[inputString]; Done.

Categories : C#

Alternative for sed ... <(cmd) and cmd | sed
If you're careful with quoting, you can do it like this: option = bash -c 'cmd "$1" "$2" | sed "s/x/y/"' sub The word "sub" at the end is arbitrary but necessary; it's there because $1 in the subshell created with bash -c is actually the second positional argument, not the first one.

Categories : Bash

ORG alternative for C++
No it's not possible to do in any C compiler that I know of. You can however create your own linker script that places the code/data/bss segments at specific addresses.

Categories : C++

What are Alternative's "some" and "many" useful for?
I tend to see them in Applicative parser combinator libraries. a :: Parser [String] a = some (string "hello") and I see many used for purpose in the default definitions of Parsing in parsers. I think Parsec being the primary example of a parser combinator library hides the use of some/many since it redefines things like (<|>).

Categories : Haskell

sql if else alternative actions
you could put action do in the "CATCH" part of your exception. BEGIN SELECT fooID into dummy FROM Foo WHERE FooID = :new.FooID; --action1 EXCEPTION WHEN NO_DATA_FOUND THEN --action2 END

Categories : SQL

Is there an alternative for UDDI?
UDDI is out of the scene these days. People are moving towards semantic web services. WSMO and OWL-s are major initiatives for semantic web services. These solutions can provide more precise results.

Categories : Web Services

Alternative to Publishing on WAS in RAD
you can try was development profile or liberty profile. if you don't have enough money :) you can use tomcat and embedded ejb container as alternative.. it would be faster ..but you will need to take care while packaging to tomacat and to websphere

Categories : Eclipse

PDO last insert id Alternative?
Sorry if I get this wrong but do you want to execute this query once with your current DB Tables? And I guess both tables have the same amount of rows(and in order of each other)? If you split those up you will get: Employee table for example: - employee_id(auto_increment) - employee_firstname - employee_lastname - employee_document_id - +whatever you want etc Document table for example: - document_id(auto_increment) - document_name - document_path - document_employee_id - +whatever you want etc. If this is what you mean, than I think the following would work: 1: Setup PDO(The editor didn't work for me that's why ">") <?php $config['db'] = array( 'host' => 'host', 'username' => 'username', 'password' => 'password', 'd

Categories : PHP

php 5.4 magic_quotes_gpc alternative?
Its better to use prepared statements as suggested here for security reasons. Mysql_real_escape_string might not be suffiecient to prevent sql injection e.g. because multibyte character sets can be abused despite the escape function ().mysql_real_escape_string() versus Prepared Statements. Prepared statements in PHP can be used like this: $stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)"); $stmt->bindParam(1, $name); $stmt->bindParam(2, $value); More information on prepared statements in PHP. So in conclusion, if you have the possibility to change your application to prepared statements, that would be the best way to handle. UPDATE (totally not recommended) If you really want to keep the state, use addslashes() for every $GET and $POST variable.

Categories : PHP

Alternative to enum in PHP
I use php bitfields usually Improve this PHP Bitfield Class for settings/permissions? While that question relates to permissions it can easily be changed to use account state

Categories : PHP

What is the alternative of the activex?
I have two things in mind for such type of communication: ActiveX and Java applet. But in both cases the end used has to install something. You can do nothing with desktop app with JavaScript only due to security reasons.

Categories : Jquery

Alternative to captcha
Other way you can do like: When form is getting open, then generate some long token key Store this long token key on one table as well. After submitting the form, check for the token key, if exists, then insert and remove that token key from table as well. If token key not found on table, then ignore insertion of data.

Categories : PHP

Alternative to mcdropdown
How about Select2? It's different visually, but I think that the search functionality is faster than clicking around. It also displays subcategories in a vertical format.

Categories : Javascript

MediaMetadataRetriever alternative?
Yes, there are an external library called FFmpegMediaMetadataRetriever. You can do the same actions like with the other class and it doesn´t fails (Unlike the API´s class that sometimes breaks without a reason at determinated positions). But it is under development and you can´t extract the exact frame and not only the key-frames yet. I suppose in one week it will be ready.

Categories : Android

Non-GPL alternative to db4o
Try OrmLIte . It has Android support, works fine and the API is relatively friendly. It uses the ISC license, similar to BSD. Also, note that db40 has a commercial license as well, if that's an option.

Categories : Android

alternative to foreignObject for IE9
I don't think it's possible to make foreignObject work in IE9. But for your particular task why not just render the user icon and name with <image> and <text> elements?

Categories : Javascript

Alternative of TabAcitivity
use Fragments as an alternative of TabActivity . To get a feel like Tabs you can do this. Use a FragmentActivity. Add different Fragments in it. And use ViewPager to switch between different fragments.

Categories : Android

php alternative to Application_Start in c#
In php each script sequentially runs through all code and then dies. So, if I understand your question properly you basically want to build the caching system into the top of your script. On my simpler projects I simply include a file (I called it assign.inc) which handles all my site wide/global tasks. It loads first on every page and sets up my session/db connection etc. On my bigger projects I wrote all traffic through index.php (via .htaccess) this initiates my CMS class which does everything though __construct. Does that help?

Categories : PHP

Alternative to PHP eval?
$2 is not a valid PHP variable name: http://www.php.net/manual/en/language.variables.basics.php It must start with an alphabetical character. A regex detailin the allowable format is in above linked page. In the greater scheme of things, you should NOT be using eval(). It's a highly dangerous function. Why not simply have it as PHP code and include() it? include.php: <?php $var = new KoolDatePicker('datepicker'); $var->id="field_2" $var->scriptFolder = '/KoolPHP'; main.php: <?php include('include.php');

Categories : PHP

php alternative to explode
You could use strstr($_SERVER['REQUEST_URI'], "?", TRUE). Alternatively, you could use strtok($_SERVER['REQUEST_URI'], "?"). It should stop matching after it's satisfied. As an aside, you shouldn't not use a PHP function because you heard [citation needed] that it was slow. You should use the appropriate tool for the job, and if that's too slow after finding a performance issue, measuring it and determining it's your use of that function, then consider refactoring.

Categories : PHP

ruby best way to get alternative value
arr = ["Cat","Mouse"] arr.shuffle! hero = arr.pop villain = arr.pop Or, you can simple write: hero, villain = arr.shuffle! (no splat(*) needed)

Categories : Ruby On Rails



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