w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
how to pass variable from python to shell script when shell script is getting called inside python script
You can: Step through the list, and then call mail.sh once for each file. This is the most reliable way. Convert the items in the list to a space delimited string, and then pass it in to mail.sh (assuming mail.sh is setup correctly, it should accept multiple arguments). What you cannot do is pass ['a.txt','b.txt','c.txt'] wholesale to the script.

Categories : Python

How to calculate float numbers in shell script?
Your problem isn't floating-point, it's that you can't build a variable name like this. If you were using a strict POSIX shell, you would need to use eval to do this: tmp=$( echo "scale=7; ( $zmin + $j - 1 ) * step" | bc -l ) eval "z_$j=$tmp" However, the for loop you are using is not a POSIX feature, which implies you are using bash or some other shell that also supports arrays, so you should use one. for ((j=1; j<=b; j++)) do z[j]=$( echo "scale=7; ( $zmin + $j - 1 ) * $step " | bc -l ) zup[j]=$( echo "scale=7; ${z[j]} + $step" | bc -l ) echo "z[$j]=${z[j]} && zup[$j]=${zup[j]}" done

Categories : Shell

Compare two files without sorting them using shell script
AFAICR, cmp returns true if the files are the same. Therefore it is not surprising that the if statement printed nothing; the files are different. You need an else clause that finds the three words in file2 and truncates them to just three characters: if cmp -s filea fileb then cat fileb else { grep elephant fileb grep snake fileb grep pony fileb } | sed 's/(...).*/1/' fi

Categories : Bash

unable to access variable declared in ksh script to csh script using shell script
The ksh script is not doing what you think it is doing when used by ksh; it sets $1 first to MyUser=root and then MyPassword=shroot. However, when you source it from your C shell script, because the syntax is compatible with C shell (checked with tcsh), you would set the two variables. If you sourced the script from a Bourne-shell derivative, the exit at the end of the ksh script would cause the shell to exit; it does not seem to cause the C shell to exit. So, what you've got is a weird hybrid. Normally, you stick to one language and use it exclusively. Where you need to use another shell, you can do so, but you simply run the script written for the other shell. You can communicate to the other script with environment variables. You don't normally try writing sourceable code that ca

Categories : Shell

Compare variable with integer in shell?
Arithmetic needs to be done between (( and )): if (( $counter > 5 )) Incidentally, you can also leave off the $ in arithmetic, though it doesn't hurt to keep it.

Categories : Bash

Shell Script with environment variable
It isn't possible for your program to change the environment of the parent process, which is what you seem to be trying to do. What you can do instead, however, is to have your program simply print the desired output, and call it using eval. $ ./cprog "wibble" TEST=wibble $ eval `./cprog "wibble"` $ echo ""TEST" is now equal to "$TEST"" "TEST" is now equal to "wibble" $

Categories : C

awk: assigning a shell variable in awk script
One way: Use the redirection inside your awk command and print your result in the END block. And use command substitution to read the result in a shell variable: my_var=$(awk '{ some processing; print "your output" >>file2 } END { print NR }' file1)

Categories : Shell

Subtracting one/more columns by a variable using shell script
Something like this? $ awk '{print $1 - 5, $2}' file 27 Mars 35 Cadburys 20 Milky Or even better: $ discount=5 $ awk -v v=$discount '{print $1 - v, $2}' file 27 Mars 35 Cadburys 20 Milky

Categories : Shell

Pass in variable from shell script to applescript
Shell variables doesn't expanding inside single quotes. When want pass shell variable to osascript you need to use double "" quotes. The problem is, than you must escape double quotes needed inside the osascript, like: the script say "Hello" using "Alex" you need escape quotes text="Hello" osascript -e "say "$text" using "Alex"" This not very readable, therefore it much better to use the bash's heredoc feature, like text="Hello world" osascript <<EOF say "$text" using "Alex" EOF And you can write multiline script inside for a free, it is much better than using multiple -e args...

Categories : Bash

Copy a variable in shell script (Linux)
Note that cp is used to copy files and directories. To define variables, you just have to use the following syntax: v=$1 Example $ cat a echo "var v=$v" v=$1 echo "var v=$v" $ ./a 23 <---- we execute the script var v= <---- the value is not set var v=23 <---- the value is already set

Categories : Linux

Shell script: variable scope in functions
Try this (amended version of the script) — it seems to work for me. I decline to test to 20 levels deep, though; at 8 levels deep, each of the three top-level directories occupies some 50 MB on a Mac file system. #!/bin/bash echo "Generating folders:" toplevel=$PWD GEN_DIRS() { cur=${1:?} max=${2:?} for i in 1 2 3 do dirname=$RANDOM if [ $cur -le $max ] then ( echo "Directory: $PWD/$dirname" mkdir $dirname cd $dirname GEN_DIRS $((cur+1)) $max ) else echo "Symlink: $PWD/$dirname" ln -s $toplevel "./$dirname" fi done } GEN_DIRS 1 ${1:-4} Lines 6 and 7 are giving names to the positional parameters ($1 and $2) passed to the functio

Categories : Function

Execute Shell Script from python with variable
Like this ? subprocess.call(['test.sh', str(domid)]) Documentation is available on the python website

Categories : Python

how to pass variable from shell script to sqlplus
You appear to have a heredoc containing a single SQL*Plus command, though it doesn't look right as noted in the comments. You can either pass a value in the heredoc: sqlplus -S user/pass@localhost << EOF @/opt/D2RQ/file.sql BUILDING exit; EOF or if BUILDING is $2 in your script: sqlplus -S user/pass@localhost << EOF @/opt/D2RQ/file.sql $2 exit; EOF If your file.sql had an exit at the end then it would be even simpler as you wouldn't need the heredoc: sqlplus -S user/pass@localhost @/opt/D2RQ/file.sql $2 In your SQL you can then refer to the position parameters using substitution variables: ... }',SEM_Models('&1'),NULL, ... The &1 will be replaced with the first value passed to the SQL script, BUILDING; because that is a string it still needs to be enclosed i

Categories : SQL

AppleScript "do shell script" ignores PATH Variable
When you invoke bash as an interactive login shell, the paths in /etc/paths and /etc/paths.d/* are added to PATH by /usr/libexec/path_helper, which is run from /etc/profile. do shell script invokes bash as sh and as a non-interactive non-login shell, which does not read /etc/profile. You can run path_helper manually though: do shell script "eval `/usr/libexec/path_helper -s`; echo $PATH"

Categories : Android

How can I pass a variable to a query inside a shell script?
Please try to remove the single quotes around your variable: they prevent your variable to be interpreted (contrary to double quotes). That should be: SELECT email FROM table WHERE partner = ${destination};

Categories : Oracle

Linux Shell-Script And Recursion, Variable not retaining value
The problem is this line: lastfib=$c It should be: lastFib=$c # ^ # Capital F Variable names in bash are case-sensitive.

Categories : Bash

Replace line in variable with string in shell script
crontab -l | sed '/myscript.sh/ s/^([^ ][^ ]*) [^ ][^ ]* /1 '"$1" '/' This will show the updated contents. The pattern matches and remembers a sequence of non-blanks at the start of the line, followed by a blank, a sequence of one or more non-blanks, and another blank, and replaces that with the remembered pattern, a space, the value in $1 and a blank. If you use update.sh 7,8,9,10,11, then you get 0 7,8,9,10,11 in your crontab. You can capture the output of that command in a variable and then echo it (carefully; use double quotes) into crontab to change the actual entry. It is conceivable that you could do: crontab -l | sed '/myscript.sh/ s/^([^ ][^ ]*) [^ ][^ ]* /1 '"$1" '/' | (sleep 1; crontab) The sleep gives crontab -l a chance to fetch the current value before it is clobbere

Categories : Bash

How to pass a string variable as a shell script argument?
You'll want to call the command as follows: Process process = new ProcessBuilder().command("sh", "/path/shell.sh", var1, var2); Scanner scan = new Scanner(process.getInputStream()); while(scan.hasNextLine()) { //... } //... scan.close(); process.destroy(); You'll probably want to wrap that in a try-catch block too.

Categories : Java

Passing variable from c program to shell script as argument
shell script (a.sh): # iterates over argument list and prints for (( i=1;$i<=$#;i=$i+1 )) do echo ${!i} done C code: #include <stdio.h> int main() { char arr[] = {'a', 'b', 'c', 'd', 'e'}; char cmd[1024] = {0}; // change this for more length char *base = "bash a.sh "; // note trailine ' ' (space) sprintf(cmd, "%s", base); int i; for (i=0;i<sizeof(arr)/sizeof(arr[0]);i++) { sprintf(cmd, "%s%c ", cmd, arr[i]); } system(cmd); }

Categories : C

Using an environment variable for java classpath not working within shell script
The symptoms you describe are rather puzzling. I can't see the problem (the script looks correct), but I've got an idea on how to start tracking it down. Get rid of the commented out lines from the script. Add a #!/bin/sh line to the start of the script to make sure that you are actually using the right shell to execute it. (It is always a good idea to do this ... even if you think that you will get the right shell by default. That might change, depending on the platform.) To figure out what the shell is doing, add set -vx as after the #!/bin/sh line. The "-v" says echo each script line read, and the "-x" says echo the actual command lines that are executed. This will tell you exactly what commands are being run ... so that you can figure out what the command arguments really are

Categories : Java

addition of values of variable and convert into hexadecimal in shell script
You can use parameter expansion to replace commas with pluses. Then, use arithmetic expansion to do the calculation. Finally, use printf to do the conversion and format the output: printf '%03x ' $(( ${variable//,/+} ))

Categories : Shell

Shell "groups" command won't read variable when launched by a script.sh
I've made a simple bash script. Here is, I hope It work for you: #!/usr/bin/env bash FT_USER=arti groups $FT_USER supposing arti isn't a valid user, script's output is: bash~$ ./test groups: arti: no such user NOte: I have saved the script content into a file called: test, which is executable. :)

Categories : Unix

Execute shell script in gruntfile and assign result to variable
Although I'm still unclear on why the method above is not working, and welcome any feedback, after a bit of research, I found shelljs, which I was able to use to solve my problem. Since shelljs can exec shell commands synchronously, I don't have to work with callbacks when I really want things to block: module.exports = (grunt) -> shell = require 'shelljs' envvar = shell.exec('./bin/get_envvar.sh', {'silent':true}).output grunt.initConfig pkg: grunt.file.readJSON('package.json') env: dev: ENV_VAR: envvar simplemocha: options: timeout: 30000 reporter: 'spec' compilers: 'coffee:coffee-script' all: src: ['Tests/**/*.coffee'] grunt.registerTask 'test', ['env', 'simplemocha'] A lot cleaner, too! References:

Categories : Node Js

Translating shell script into Windows command shell script (batch)
for /L makes a count-controlled loop in batch. mkdir remains mkdir. @echo off for /L %%y in (1,1,9) do mkdir week_0%%y mkdir week_10

Categories : Shell

Shell script cannot be executed from some directories even though its directory is added to the "PATH" variable
You should add the complete path to your bin directory, not just bin. If bin is in your $HOME, you can add $HOME/bin or ~/bin.

Categories : Linux

How to compare the querystring parameters saved in a variable, and save the variable in cookie and compare on each page
Try this <script type="text/javascript"> $(document).ready( function(){ var params = getUrlVars(); var utm_campaign = params["utm_campaign"]; var utm_content = params["utm_content"]; if( utm_campaign === "percentoff" && utm_content == "COUPON_CODE_HERE") { alert("hi"); } if( utm_campaign === "freeship" && utm_content === "COUPON_CODE_HERE") { alert("hello"); } }); function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[

Categories : Javascript

How to launch a shell script with an emacs keybinding, passing the word under the cursor as a variable
You could try something like this: (defvar script-name "/foo/bar/my-script") (defun call-my-script-with-word () (interactive) (shell-command (concat script-name " " (thing-at-point 'word)))) (global-set-key (kbd "C-c o") 'call-my-script-with-word)

Categories : Linux

makefile shell and pipe
What you've stumbled upon is probably the fact, that parentheses are not escapeable in GNU Make. You can work around this problem by using helper script: TESTS := $(shell ./grep.sh test_cases_file ) all: $(TESTS) Where grep.sh is: cat $1 | egrep -v ^s*(#|$)

Categories : Shell

Shell pipe system in C
You don't need to pass the end argument, instead increment the pointer to your command array. You are passing the initial array to the execvp call so it tries to execute ls multiple times. Further, you need a break statement after setting the listaCommand[cont] to NULL because after the iteration cont is incremented. Also I think you need to protect the execvp call so that the parent does not call it after the processing is done. #include <stdio.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #include <sys/wait.h> #define fatal() exit(1) void pipes (char *listaCommand[], char **argv) { printf("pipes %s ", listaCommand[0]); int cont = 0; for (;listaCommand[cont]; cont++) { if (listaCommand[cont][0] == '|'){

Categories : C

Shell command works in shell but not in shell script
You are using single quotes in this command: filelist=$(grep '$incstring' -rl --include=*.{h,cpp} pathToFiles) Single quotes inhibit variable expansion. That is, you're looking for the literal string $incstring rather than the contents of that variable. This command, as shown here, would not have worked on the command line either. From the bash(1) man page: Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Replace the single quotes with double quotes: filelist=$(grep "$incstring" -rl --include=*.{h,cpp} pathToFiles)

Categories : Shell

Shell - Pipe to multiple commands in a file
When you execute tee >(some_command) bash creates a subshell to run some_command. The subshell's stdin is assigned to the reading half of a pipe. bash leaves the name of this pipe on the command line, so that tee will pump its input into the pipe. The subshell's stdout and stderr are left unchanged, so they are still the same as tee's. So, when you execute tee >(some_command) | some_other_command Now, bash first creates a process to run tee, and assigns its stdout to the writing half of a pipe, and another process to run some_other_command, with its stdin assigned to the reading half of the same pipe. Then it creates another process to run some_command, as above, assigning its stdin to the reading half of another pipe, and leaving its stdout and stderr unchanged. However, stdo

Categories : Bash

How to pipe the output of shell command to from a rake task
Rakefile require 'rake' task :shell_me do sh './blah' end blah (executable via chmod +x blah + shebang) #!/usr/bin/ruby puts "HI!" Shell command: $ rake shell_me > blah.log blah.log: HI!

Categories : Shell

Storing two float values in a single float variable
Following Gnietschow's recommendation I adapted the algo of YellPika. (It's C# for Unity 3d.) float Pack(Vector2 input, int precision) { Vector2 output = input; output.x = Mathf.Floor(output.x * (precision - 1)); output.y = Mathf.Floor(output.y * (precision - 1)); return (output.x * precision) + output.y; } Vector2 Unpack(float input, int precision) { Vector2 output = Vector2.zero; output.y = input % precision; output.x = Mathf.Floor(input / precision); return output / (precision - 1); } The quick and dirty testing produced the following stats (1 million random value pairs in the 0..1 range): Precision: 2048 | Avg error: 0.00024424 | Max error: 0.00048852 Precision: 4096 | Avg error: 0.00012208 | Max error: 0.00024417 Precision: 8192 | Avg error: 0.0

Categories : C#

Running two node servers from a single shell command using a shell script
Your command does not work because you are trying to have two processes running in the same shell. Instead, you should 'spawn' the node processes into different processes. Try this command: node project/rest.js & node static-server.js &

Categories : Node Js

Running a login shell using sudo inside a shell script on Mac OSX
Your shell is interpreting the $HOME variable in the heredoc, before the input reaches the su shell. You need to escape the $: bash-3.2$ sudo su -l root <<EOF > echo $HOME > echo $HOME > EOF /Users/kevin /var/root The real question is why does it work on your Linux box.

Categories : Osx

Use shell script wrapper to enter commands into a new shell
If the sequence of commands is fixed (does not change from run to run), you might be able to use: #!/bin/sh Dbm2 <<EOF table THE_TABLE ...other commands... EOF ls # Just to demonstrate that the shell continues The <<EOF notation is a here-doc. The lines up to the line containing EOF are the input to the command Dbm2. If the content of the commands needs to vary, you may be able to pipe the input to Dbm2. In your script, if you manually enter commands to Dbm2 and then quit, your original shell script should continue. The table THE_TABLE line would be treated as another shell command and would, most likely, fail.

Categories : Shell

compare to_char with float
Welcome to Stack Overflow! Your WHERE clause is usually used to limit your SELECT statement to rows that satisfy the WHERE condition (i.e. WHERE myTable.favoriteNumber = 5). Alternatively, you can have a boolean expression in there. WHERE 1=1 evaluates to WHERE TRUE. Because it's TRUE, all rows are returned. WHERE 0=2 evalutes to WHERE FALSE and therefore no rows are returned, because 0 does not equal 2 in any row. In any case, think about it logically. In order for you to get a set of rows, you need to give it parameters. How does the database know which rows you want? First you have to select the fields using SELECT. Which table? Define FROM. Do you want a subset of rows that meet certain conditions? Add a WHERE. Where can I store the values from the row? Add an INTO. Jus

Categories : Oracle

How can I execute a shell-script in a Bash sub-shell?
You can do the same but without eval. with-env-overrides() { ( source $HOME/.env-overrides "$@" ) } Example: $ cat ~/.env-overrides export A=1000 $ export | grep ^A= $ with-env-overrides export | ^grep A= declare -x A="1000" As you can see, in the second case, you've got an environment with the A variable.

Categories : Linux

How to pass several shell variables to awk in shell script?
ls -l | nawk -v r="3,5" 'BEGIN{split(r,a,",")}{for(i in a)printf $a[i]" ";print " "}' Now you can simply change your r variable in shell script and pass it on. or you can configure it in your shell script and use r=$your_list_var What ever fields numbers are present in $your_list_var will be printed by awk command. The example above print 3rd and 5th fields of ls -l output.

Categories : Linux

Compare `float` and `float64` in python
You should not compare floats with equality, in any programming language, because you can never know that they are exactly equal. Instead, you should test whether their difference is smaller than a tolerance: if abs(a - b) < 1e-10 So this problem doesn't have to do with the difference between float and float64 (Python converts them automatically), but with the fundamental problem of comparing floats for equality. See also What's wrong with using == to compare floats in Java?

Categories : Python



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