bash-function

In bash tee is making function variables local, how do I escape this?

╄→尐↘猪︶ㄣ 提交于 2020-01-15 08:17:30
问题 I have stucked with a bash scipt which should write both to stdout and into file. I'm using functions and some variables inside them. Whenever I try to redirect the function to a file and print on the screen with tee I can't use the variables that I used in function, so they become local somehow. Here is simple example: #!/bin/bash LOGV=/root/log function var() { echo -e "Please, insert VAR value:\n" read -re VAR } var 2>&1 | tee $LOGV echo "This is VAR:$VAR" Output: [root@testbox ~]# ./var

bash aliases not recognized by a bash function: sunspot_rails, jruby, rspec

守給你的承諾、 提交于 2019-12-24 10:39:44
问题 Aliases below for running sunspot in the background work Aliases below for finding and killing those instances work ENV variables for the sunspot ports are accessible But, Functions for running sunspot, processing command, and killing sunspot only work after I source .bashrc outside of the function. $user_id is set before this sunspot_ports() gets called and prints properly when first logging in rebash is an alias for source ~.bashrc I have aliases for development and production as well -

Spawn a background process in a bash function

六月ゝ 毕业季﹏ 提交于 2019-12-23 15:59:40
问题 I am working on writing a Bash function to start a server that needs to be started from a certain folder, but I don't want starting this server to impact my current work. I've written the following: function startsrv { pushd . cd ${TRUNK} ${SERVERCOMMAND} & popd } My variables are all set, but when this executes, I get an error regarding an unexpected semicolon in the output, it appears that Bash is inserting a semicolon after the ampersand starting ${SERVERCOMMAND} in the background. Is

How to launch a Bash function using Git alias

拈花ヽ惹草 提交于 2019-12-10 20:27:43
问题 I want to use a Git alias in ~/.gitconfig so that it calls a bash function, if it is defined, otherwise call the regular git checkout . This is what I have devised: cat ~/.gitconfig ... [alias] ... co = !(compgen -A function vxzExecuteGitCheckout >/dev/null && vxzExecuteGitCheckout ) || git checkout The problem is that Git uses /bin/sh (which happens to be dash in my case) and it barfs on compgen since it is a bash builtin. Any way making sure that Git uses bash to execute this command? Note

read stdin in function in bash script

浪子不回头ぞ 提交于 2019-11-30 04:14:31
I have some set of bash functions which output some information: find-modelname-in-epson-ppds find-modelname-in-samsung-ppds find-modelname-in-hp-ppds etc ... I've been writing functions which read output and filter it: function filter-epson { find-modelname-in-epson-ppds | sed <bla-blah-blah> } function filter-hp { find-modelname-in-hp-ppds | sed <the same bla-blah-blah> } etc ... But the I thought that it would be better do something like this: function filter-general { (somehow get input) | sed <bla-blah-blah> } and then call in another high-level functions: function high-level-func { #

Defining bash function body using parenthesis instead of braces

血红的双手。 提交于 2019-11-29 10:19:58
This script demonstrates defining a bash function with parenthesis verses with braces. The parenthesis have the nice effect of making environment variables created in the function "local", I guess because the function body is executed as a sub-shell. The output is: A=something A= B=something B=something The question is if this is allowed syntax for defining a function. #!/bin/bash foo() ( export A=something echo A=$A ) bar() { export B=something echo B=$B } foo echo A=$A bar echo B=$B Carl Norum Yes, that syntax is allowed. As described in the bash man page , the definition of a bash function

Defining bash function body using parenthesis instead of braces

岁酱吖の 提交于 2019-11-28 03:16:12
问题 This script demonstrates defining a bash function with parenthesis verses with braces. The parenthesis have the nice effect of making environment variables created in the function "local", I guess because the function body is executed as a sub-shell. The output is: A=something A= B=something B=something The question is if this is allowed syntax for defining a function. #!/bin/bash foo() ( export A=something echo A=$A ) bar() { export B=something echo B=$B } foo echo A=$A bar echo B=$B 回答1:

read stdin in function in bash script

狂风中的少年 提交于 2019-11-26 20:19:19
问题 I have some set of bash functions which output some information: find-modelname-in-epson-ppds find-modelname-in-samsung-ppds find-modelname-in-hp-ppds etc ... I've been writing functions which read output and filter it: function filter-epson { find-modelname-in-epson-ppds | sed <bla-blah-blah> } function filter-hp { find-modelname-in-hp-ppds | sed <the same bla-blah-blah> } etc ... But the I thought that it would be better do something like this: function filter-general { (somehow get input)