Set environment variable with cron. Not working - variables

How can I set for example with cronjob
1/* * * * * bash -c 'export TZ=Europe/London'
1/* * * * * bash -c '. /path/to/script.sh'
This script has multiple exports which is getting the timezone offset and would like that cronjob update the system var TZ with that one.
If I run it from shell it works with
". /path/to/script.th" as source but not in a cronjob.
At least how to set the environment variables with cronjob.
I also have tried that the script writes into the /etc/environment
TZ=Europe/London
and cronjob to set -a;. /etc/environment; set +a;
None are working but they do from shell.
Here is my script. What are my options from here when the script is ran by cronjob or anything else...Also tried to make it run with supervisord...same result.
Everything is working running locally from shell, but can't figure out how to modify the system "$TZ" environment with a script or from cronjob.
The script writes into the /etc/environment but when I set it from cron still won't update but it will from shell.
I know it all works from current shell but /etc/environment should be available to all.
I have edited so the way to go is write with the script into the /etc/profile.d/custom.sh
This works also inside a docker container to update periodicaly environmental variable if needed.
#!/bin/bash
#######################
## Preload variables ##
#######################
. /etc/profile
. ~/.bash_profile
. ~/.bashrc
#############################
## Get Boardtime from API ##
#############################
boardtime=$(curl -s http://server/api/get-time \
-u user:pass \
-d locale='en_US' | \
grep -oP '(?<=boardTime":")[^","boardTimeLocalized"]*' | \
sed -r -e 's/^.{8}/& /' -e 's/[^ ]{2}/&:/5g' | \
sed 's/:$//')
formatted_boardtime=$(date -d "$boardtime" "+%a, %e %b %Y %H:%M:%S %z")
echo -ne "\nLocaltime is $formatted_boardtime!\n"
###################################
## Get timezone offset from ship ##
###################################
minutes=$(curl -s http://server/timezone/currentOffset.txt | grep -oP "[-+][0-9]{0,9}/|[0-9]{0,9}")
echo -ne "\nTimezone offset is $minutes\n"
((h=$minutes / 60))
#############################
## Set Offset Symbol Value ##
#############################
symbol=$(echo $minutes | grep -oP "[-]")
digit=$(echo $h | grep -oP "[0-9]{2,4}")
if [[ $symbol == "-" ]] && [[ $digit ]]; then
offset="-"$h"00"
elif [[ $symbol != "-" ]] && [[ $digit ]]; then
offset="+"$h"00"
elif [[ $symbol == "-" ]] && [[ ! $digit ]]; then
offset="-0$(echo "$h" | grep -oP '[0-9]{0,4}')00"
else
offset="+0$(echo "$h" | grep -oP '[0-9]{0,4}')00"
fi
##########################
## Set Current timezone ##
##########################
localtime=$(echo $formatted_boardtime | sed -E "s/([-+][0-9]{4})$/"$offset"/")
if [[ $symbol == "-" && $offset == -1100 ]]; then
export TZ="US/Samoa"
elif [[ $symbol == "-" && $offset == -1000 ]]; then
export TZ="Pacific/Honolulu"
elif [[ $symbol == "-" && $offset == -0900 ]]; then
export TZ="America/Nome"
elif [[ $symbol == "-" && $offset == -0800 ]]; then
export TZ="America/Los_Angeles"
elif [[ $symbol == "-" && $offset == -0700 ]]; then
export TZ="America/Denver"
elif [[ $symbol == "-" && $offset == -0600 ]]; then
export TZ="America/Cancun"
elif [[ $symbol == "-" && $offset == -0500 ]]; then
export TZ="America/Lima"
elif [[ $symbol == "-" && $offset == -0400 ]]; then
export TZ="America/Santiago"
elif [[ $symbol == "-" && $offset == -0300 ]]; then
export TZ="America/Bahia"
elif [[ $symbol == "-" && $offset == -0200 ]]; then
export TZ="America/Noronha"
elif [[ $symbol == "-" && $offset == -0100 ]]; then
export TZ="Atlantic/Azores"
elif [[ $symbol != "-" && $offset == +0000 ]]; then
export TZ="Europe/London"
elif [[ $symbol != "-" && $offset == +0100 ]]; then
export TZ="Europe/Berlin"
elif [[ $symbol != "-" && $offset == +0200 ]]; then
export TZ="Europe/Athens"
elif [[ $symbol != "-" && $offset == +0300 ]]; then
export TZ="Asia/Qatar"
elif [[ $symbol != "-" && $offset == +0400 ]]; then
export TZ="Asia/Dubai"
elif [[ $symbol != "-" && $offset == +0500 ]]; then
export TZ="Indian/Maldives"
elif [[ $symbol != "-" && $offset == +0600 ]]; then
export TZ="Asia/Thimbu"
elif [[ $symbol != "-" && $offset == +0700 ]]; then
export TZ="Asia/Bangkok"
elif [[ $symbol != "-" && $offset == +0800 ]]; then
export TZ="Asia/Hong_Kong"
elif [[ $symbol != "-" && $offset == +0900 ]]; then
export TZ="Asia/Tokyo"
elif [[ $symbol != "-" && $offset == +1000 ]]; then
export TZ="Australia/Melbourne"
elif [[ $symbol != "-" && $offset == +1100 ]]; then
export TZ="Pacific/Ponape"
elif [[ $symbol != "-" && $offset == +1200 ]]; then
export TZ="Pacific/Fiji"
elif [[ $symbol != "-" && $offset == +1300 ]]; then
export TZ="Pacific/Apia"
elif [[ $symbol != "-" && $offset == +1400 ]]; then
export TZ="Pacific/Kiritimati"
fi
echo -ne "\nLocaltime is $localtime!\n"
echo -ne "\nTimezone matching offset is set $TZ!\n"
echo "$TZ" > /etc/timezone
echo "TZ=$TZ" > /etc/profile.d/custom.sh
###########################################################
## Restart postfix to apply new timezone also to postfix ##
###########################################################
/usr/sbin/postfix stop && /usr/sbin/postfix start

Can mark as a working solution for this using as follows then:
The solution is create a /etc/profile.d/custom.sh
Write in there you environment variable or your script can write in there and create the file with the content you need.
Inside there simply add all the environments you need like
export TZ=Europe/London
export MYENV=value
export etc..
..

Related

What does this awk command do?

What does this awk command do?
awk 'NR > 1 {for(x=1;x<=NF;x++) if(x == 1 || (x >= 4 && x % 2 == 0))
printf "%s", $x (x == NF || x == (NF-1) ? "\n":"\t")}' depth.txt
> depth_concoct.txt
I think
NR > 1 means it starts from second line,
for(x=1;x<=NF;x++) means for every fields,
if(x == 1 || (x >= 4 && x % 2 == 0)) means if x equals 1 or (I don' understand the codes from this part and so on)
and I know that the input file for awk is depth.txt and the output of awk will be saved to depth_concoct.txt.
What does the codes in the middle mean?
$ awk '
NR > 1 { # starting from the second record
for(x=1;x<=NF;x++) # iterate every field
if(x == 1 || (x >= 4 && x % 2 == 0)) # for 1st, 4th and every even-numbered field after 4th
printf "%s", # print the field and after it
$x (x == NF || x == (NF-1) ? "\n":"\t") # a tab or a newline if its the last field
}' depth.txt > depth_concoct.txt
(x == NF || x == (NF-1) ? "\n":"\t") is called conditional operator, in this context it's basically streamlined version of:
if( x == NF || x == (NF-1) ) # if this is the last field to be printed
printf "\n" # finish the record with a newline
else # else
printf "\t"` # print a tab after the field
you can rewrite it as below, which should be trivial to read.
$ awk `NR>1 {printf "%s", $1;
for(x=4;x<=NF;x+=2) printf "\t%s", $x;
print ""}' inputfile > outputfile
the complexity of the code is sometimes just an implementation detail.
prints first and every second field starting from the 4th.
Assume your file has 8 fields, this is equivalent to
$ awk -v OFS='\t' 'NR>1{print $1,$4,$6,$8}' inputfile > outputfile

Awk output formatting

I have 2 .po files and some word in there has 2 different meanings
and want to use awk to turn it into some kind of translator
For example
in .po file 1
msgid "example"
msgstr "something"
in .po file 2
msgid "example"
msgstr "somethingelse"
I came up with this
awk -F'"' 'match($2, /^example$/) {printf "%s", $2": ";getline; printf "%s", $2}' file1.po file2.po
The output will be
example:something example:somethinelse
How do I make it into this kind of format
example : something, somethingelse.
Reformatting
example:something example:somethinelse
into
example : something, somethingelse
can be done with this one-liner:
awk -F":| " -v OFS="," '{printf "%s:", $1; for (i=1;i<=NF;i++) if (i % 2 == 0)printf("%s%s%s", ((i==2)?"":OFS), $i, ((i==NF)?"\n":""))}'
Testing:
$ echo "example:something example:somethinelse example:something3 example:something4" | \
awk -F":| " -v OFS="," '{ \
printf "%s:", $1; \
for (i=1;i<=NF;i++) \
if (i % 2 == 0) \
printf("%s%s%s", ((i==2)?"":OFS), $i, ((i==NF)?"\n":""))}'
example:something,somethinelse,something3,something4
Explanation:
$ cat tst.awk
BEGIN{FS=":| ";OFS=","} # define field sep and output field sep
{ printf "%s:", $1 # print header line "example:"
for (i=1;i<=NF;i++) # loop over all fields
if (i % 2 == 0) # we're only interested in all "even" fields
printf("%s%s%s", ((i==2)?"":OFS), $i, ((i==NF)?"\n":""))
}
But you could have done the whole thing in one go with something like this:
$ cat tst.awk
BEGIN{OFS=","} # set output field sep to ","
NF{ # if NF (i.e. number of fields) > 0
# - to skip empty lines -
if (match($0,/msgid "(.*)"/,a)) id=a[1] # if line matches 'msgid "something",
# set "id" to "something"
if (match($0,/msgstr "(.*)"/,b)) str=b[1] # same here for 'msgstr'
if (id && str){ # if both "id" and "str" are set
r[id]=(id in r)?r[id] OFS str:str # save "str" in array r with index "id".
# if index "id" already exists,
# add "str" preceded by OFS (i.e. "," here)
id=str=0 # after printing, reset "id" and "str"
}
}
END { for (i in r) printf "%s : %s\n", i, r[i] } # print array "r"
and call this like:
awk -f tst.awk *.po
$ awk -F'"' 'NR%2{k=$2; next} NR==FNR{a[k]=$2; next} {print k" : "a[k]", "$2}' file1 file2
example : something, somethingelse

Bourne Shell Conditional Operators

I am having a lot of fun playing with Bourne Shell, but I am facing a quite cryptic situation regarding conditions:
#! /bin/sh
a=1
b=2
c="0 kB/s"
if [ "$a" -eq 1 ] ; then echo "a = 1: true" ; else echo "a = 1: false" ; fi
if [ "$b" -gt 0 ] ; then echo "b > 0: true" ; else echo "b > 0: false" ; fi
if [ "$c" != "0 kB/s" ] ; then echo "c <> 0: true" ; else echo "c <> 0: false" ; fi
if [ "$a" -eq 1 ] || [ "$b" -gt 0 ] ; then echo "a = 1 or b > 0: true" ; else echo "a = 1 or b > 0: false" ; fi
if [ "$a" -eq 1 ] || [ "$b" -gt 0 ] && [ "$c" != "0 kB/s" ] ; then echo "a = 1 or b > 0 and c <> 0: true" ; else echo "a = 1 or b > 0 and c <> 0: false" ; fi
if [ true ] || [ true ] && [ false ] ; then echo "true or true and false: true" ; else echo "true or true and false: false" ; fi
gives me the following result:
a = 1: true
b > 0: true
c <> 0: false
a = 1 or b > 0: true
a = 1 or b > 0 and c <> 0: false
true or true and false: true
Short question: why don't I get a = 1 or b > 0 and c <> 0: true?
Thanks a lot for your help ...
|| and && have equal precedence, unlike in languages where the logical AND operator binds more tightly than the logical OR. This means your code as written is equivalent to
if { [ "$a" -eq 1 ] || [ "$b" -gt 0 ]; } && [ "$c" != "0 kB/s" ] ; then
echo "a = 1 or b > 0 and c <> 0: true"
else
echo "a = 1 or b > 0 and c <> 0: false"
fi
rather than the expected
if [ "$a" -eq 1 ] || { [ "$b" -gt 0 ] && [ "$c" != "0 kB/s" ]; } ; then
echo "a = 1 or b > 0 and c <> 0: true"
else
echo "a = 1 or b > 0 and c <> 0: false"
fi

Mac is getting slower. Because of pyenv or zsh, bash setting?

Suddenly my terminal is getting slower seriously!
I don't know why but I guess the cause is that something wrong pyenv or zsh, bash setting.
Here is my pyenv log When I run ls in Terminal(zsh).
+_pyenv_virtualenv_hook:1> local 'ret=0'
+_pyenv_virtualenv_hook:2> [ -n '' ']'
+_pyenv_virtualenv_hook:5> pyenv sh-activate --quiet
+pyenv:1> local command
+pyenv:2> command=sh-activate
+pyenv:3> [ 2 -gt 0 ']'
+pyenv:4> shift
+pyenv:7> case sh-activate (activate | deactivate | rehash | shell)
+pyenv:7> case sh-activate (*)
+pyenv:11> pyenv sh-activate --quiet
+ [pyenv:23] enable -f /usr/local/Cellar/pyenv/20160202/libexec/../libexec/pyenv-realpath.dylib realpath
+ [pyenv:29] '[' -z '' ']'
++ [pyenv:31] type -p greadlink readlink
++ [pyenv:31] head -1
+ [pyenv:31] READLINK=/usr/bin/readlink
+ [pyenv:32] '[' -n /usr/bin/readlink ']'
+ [pyenv:53] '[' -z '' ']'
+ [pyenv:54] PYENV_ROOT=/Users/DS/.pyenv
+ [pyenv:58] export PYENV_ROOT
+ [pyenv:61] '[' -z '' ']'
+ [pyenv:62] '[' -n '' ']'
+ [pyenv:73] '[' -z '' ']'
+ [pyenv:74] PYENV_DIR=/Users/DS
+ [pyenv:80] export PYENV_DIR
+ [pyenv:83] shopt -s nullglob
++ [pyenv:85] abs_dirname /usr/local/Cellar/pyenv/20160202/libexec/pyenv
++ [pyenv:39] local cwd=/Users/DS
++ [pyenv:40] local path=/usr/local/Cellar/pyenv/20160202/libexec/pyenv
++ [pyenv:42] '[' -n /usr/local/Cellar/pyenv/20160202/libexec/pyenv ']'
++ [pyenv:43] cd /usr/local/Cellar/pyenv/20160202/libexec
++ [pyenv:44] local name=pyenv
+++ [pyenv:45] resolve_link pyenv
+++ [pyenv:35] /usr/bin/readlink pyenv
+++ [pyenv:45] true
++ [pyenv:45] path=
++ [pyenv:42] '[' -n '' ']'
++ [pyenv:48] pwd
++ [pyenv:49] cd /Users/DS
+ [pyenv:85] bin_path=/usr/local/Cellar/pyenv/20160202/libexec
+ [pyenv:89] export PATH=/usr/local/Cellar/pyenv/20160202/libexec:/usr/local/Cellar/pyenv-virtualenv/20160202/shims:/usr/local/Cellar/pyenv/20160202/libexec:/Users/DS/.pyenv/shims:/usr/local/bin:/usr/bin:/usr/sbin:/bin
+ [pyenv:89] PATH=/usr/local/Cellar/pyenv/20160202/libexec:/usr/local/Cellar/pyenv-virtualenv/20160202/shims:/usr/local/Cellar/pyenv/20160202/libexec:/Users/DS/.pyenv/shims:/usr/local/bin:/usr/bin:/usr/sbin:/bin
+ [pyenv:91] PYENV_HOOK_PATH=:/Users/DS/.pyenv/pyenv.d
+ [pyenv:92] '[' /usr/local/Cellar/pyenv/20160202 '!=' /Users/DS/.pyenv ']'
+ [pyenv:94] PYENV_HOOK_PATH=:/Users/DS/.pyenv/pyenv.d:/usr/local/Cellar/pyenv/20160202/pyenv.d
+ [pyenv:96] PYENV_HOOK_PATH=:/Users/DS/.pyenv/pyenv.d:/usr/local/Cellar/pyenv/20160202/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks
+ [pyenv:100] export PYENV_HOOK_PATH
+ [pyenv:102] shopt -u nullglob
+ [pyenv:105] command=sh-activate
+ [pyenv:106] case "$command" in
++ [pyenv:119] command -v pyenv-sh-activate
+ [pyenv:119] command_path=/usr/local/bin/pyenv-sh-activate
+ [pyenv:120] '[' -n /usr/local/bin/pyenv-sh-activate ']'
+ [pyenv:122] shift 1
+ [pyenv:123] '[' --quiet = --help ']'
+ [pyenv:126] exec /usr/local/bin/pyenv-sh-activate --quiet
+ [pyenv-sh-activate:17] '[' -z /Users/DS/.pyenv ']'
+ [pyenv-sh-activate:25] unset FORCE
+ [pyenv-sh-activate:26] unset QUIET
+ [pyenv-sh-activate:27] unset VERBOSE
+ [pyenv-sh-activate:29] '[' 1 -gt 0 ']'
+ [pyenv-sh-activate:30] case "$1" in
+ [pyenv-sh-activate:44] QUIET=1
+ [pyenv-sh-activate:56] shift 1
+ [pyenv-sh-activate:29] '[' 0 -gt 0 ']'
+ [pyenv-sh-activate:59] no_shell=
+ [pyenv-sh-activate:60] versions=("$#")
+ [pyenv-sh-activate:61] '[' -z '' ']'
+ [pyenv-sh-activate:62] no_shell=1
+ [pyenv-sh-activate:63] OLDIFS='
'
+ [pyenv-sh-activate:64] IFS=:
+ [pyenv-sh-activate:64] versions=($(pyenv-version-name 2>/dev/null))
++ [pyenv-sh-activate:64] pyenv-version-name
+ [pyenv-sh-activate:65] IFS='
'
+ [pyenv-sh-activate:68] '[' -z 1 ']'
+ [pyenv-sh-activate:74] venv=system
+ [pyenv-sh-activate:76] '[' -n '' ']'
+ [pyenv-sh-activate:89] pyenv-virtualenv-prefix system
+ [pyenv-sh-activate:91] OLDIFS='
'
+ [pyenv-sh-activate:92] IFS=:
+ [pyenv-sh-activate:92] current_versions=($(pyenv-version-name))
++ [pyenv-sh-activate:92] pyenv-version-name
+ [pyenv-version-name:6] '[' -z '' ']'
++ [pyenv-version-name:7] pyenv-version-file
+ [pyenv-version-file:22] find_local_version_file /Users/DS
+ [pyenv-version-file:7] local root=/Users/DS
+ [pyenv-version-file:8] true
+ [pyenv-version-file:9] [[ /Users/DS =~ ^//[^/]*$ ]]
+ [pyenv-version-file:10] '[' -e /Users/DS/.python-version ']'
+ [pyenv-version-file:13] '[' -e /Users/DS/.pyenv-version ']'
+ [pyenv-version-file:17] '[' -n /Users/DS ']'
+ [pyenv-version-file:18] root=/Users
+ [pyenv-version-file:8] true
+ [pyenv-version-file:9] [[ /Users =~ ^//[^/]*$ ]]
+ [pyenv-version-file:10] '[' -e /Users/.python-version ']'
+ [pyenv-version-file:13] '[' -e /Users/.pyenv-version ']'
+ [pyenv-version-file:17] '[' -n /Users ']'
+ [pyenv-version-file:18] root=
+ [pyenv-version-file:8] true
+ [pyenv-version-file:9] [[ '' =~ ^//[^/]*$ ]]
+ [pyenv-version-file:10] '[' -e /.python-version ']'
+ [pyenv-version-file:13] '[' -e /.pyenv-version ']'
+ [pyenv-version-file:17] '[' -n '' ']'
+ [pyenv-version-file:17] break
+ [pyenv-version-file:23] '[' /Users/DS = /Users/DS ']'
+ [pyenv-version-file:25] global_version_file=/Users/DS/.pyenv/version
+ [pyenv-version-file:27] '[' -e /Users/DS/.pyenv/version ']'
+ [pyenv-version-file:29] '[' -e /Users/DS/.pyenv/global ']'
+ [pyenv-version-file:31] '[' -e /Users/DS/.pyenv/default ']'
+ [pyenv-version-file:34] echo /Users/DS/.pyenv/version
+ [pyenv-version-name:7] PYENV_VERSION_FILE=/Users/DS/.pyenv/version
++ [pyenv-version-name:8] pyenv-version-file-read /Users/DS/.pyenv/version
+ [pyenv-version-file-read:6] VERSION_FILE=/Users/DS/.pyenv/version
+ [pyenv-version-file-read:8] '[' -e /Users/DS/.pyenv/version ']'
+ [pyenv-version-file-read:22] exit 1
++ [pyenv-version-name:8] true
+ [pyenv-version-name:8] PYENV_VERSION=
+ [pyenv-version-name:11] '[' -z '' ']'
+ [pyenv-version-name:12] echo system
+ [pyenv-version-name:13] exit
+ [pyenv-sh-activate:93] IFS='
'
+ [pyenv-sh-activate:94] new_venv=system/envs/system
+ [pyenv-sh-activate:95] pyenv-virtualenv-prefix system/envs/system
+ [pyenv-sh-activate:99] '[' -z 1 ']'
+ [pyenv-sh-activate:102] echo false
+ [pyenv-sh-activate:103] exit 1
+_pyenv_virtualenv_hook:5> true
+_pyenv_virtualenv_hook:5> eval false
+(eval):1> false
+_pyenv_virtualenv_hook:5> true
+_pyenv_virtualenv_hook:7> return 0
+omz_termsupport_precmd:1> emulate -L zsh
+omz_termsupport_precmd:3> [[ '' == true ]]
+omz_termsupport_precmd:7> title '%15<..<%~%<<' %n#%m
+title:1> emulate -L zsh
+title:2> setopt prompt_subst
+title:4> [[ '' == *term* ]]
+title:8> : %n#%m
+title:10> case ansi (cygwin | xterm* | putty* | rxvt* | ansi)
+title:12> print -Pn '\e]2;%n#%m\a'
+title:13> print -Pn '\e]1;%15\<..\<%~%\<\<\a'
+update_terminalapp_cwd:1> emulate -L zsh
+update_terminalapp_cwd:4> omz_urlencode -P /Users/DS
+omz_urlencode:1> emulate -L zsh
+omz_urlencode:2> zparseopts -D -E -a opts r m P
+omz_urlencode:4> local 'in_str=/Users/DS'
+omz_urlencode:5> local 'url_str='
+omz_urlencode:6> local spaces_as_plus
+omz_urlencode:7> [[ -z -P ]]
+omz_urlencode:8> local 'str=/Users/DS'
+omz_urlencode:11> local 'encoding=UTF-8'
+omz_urlencode:12> local safe_encodings
+omz_urlencode:13> safe_encodings=( UTF-8 utf8 US-ASCII )
+omz_urlencode:14> [[ -z UTF-8 ]]
+omz_urlencode:23> local i byte ord 'LC_ALL=C'
+omz_urlencode:24> export LC_ALL
+omz_urlencode:25> local 'reserved=;/?:#&=+$,'
+omz_urlencode:26> local 'mark=_.!~*()-'
+omz_urlencode:27> local 'dont_escape=[A-Za-z0-9'
+omz_urlencode:28> [[ -z '' ]]
+omz_urlencode:29> dont_escape+=';/?:#&=+$,'
+omz_urlencode:32> [[ -z '' ]]
+omz_urlencode:33> dont_escape+='_.!~*()-'
+omz_urlencode:35> dont_escape+=']'
+omz_urlencode:39> local 'url_str='
+omz_urlencode:40> i = 1
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=/
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=/
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=U
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=U
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=s
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=s
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=e
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=e
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=r
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=r
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=s
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=s
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=/
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=/
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=D
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=D
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:41> byte=S
+omz_urlencode:42> [[ "$byte" -regex-match "$dont_escape" ]]
+omz_urlencode:43> url_str+=S
+omz_urlencode:40> ++i
+omz_urlencode:40> i <= 9
+omz_urlencode:53> echo -E /Users/DS
+update_terminalapp_cwd:4> local 'URL_PATH=/Users/DS'
+update_terminalapp_cwd:5> [[ 0 != 0 ]]
+update_terminalapp_cwd:8> printf '\e]7;%s\a' file://YuDaesungui-MacBook-Pro.local/Users/DS
+-zsh:5> build_prompt
+build_prompt:1> RETVAL=0
+build_prompt:2> prompt_status
+prompt_status:1> local symbols
+prompt_status:2> symbols=( )
+prompt_status:3> [[ 0 -ne 0 ]]
+prompt_status:4> [[ 501 -eq 0 ]]
+prompt_status:5> [[+prompt_status:5> jobs -l
+prompt_status:5> [[+prompt_status:5> wc -l
+prompt_status:5> [[ ' 0' -gt 0 ]]
+prompt_status:7> [[ -n '' ]]
+build_prompt:3> prompt_virtualenv
+prompt_virtualenv:1> local 'virtualenv_path='
+prompt_virtualenv:2> [[ -n '' ]]
+build_prompt:4> prompt_context
+prompt_context:1> [[ DS != ]]
+prompt_context:2> prompt_segment black default '%(!.%{%F{yellow}%}.)DS#%m'
+prompt_segment:1> local bg fg
+prompt_segment:2> [[ -n black ]]
+prompt_segment:2> bg='%K{black}'
+prompt_segment:3> [[ -n default ]]
+prompt_segment:3> fg='%F{default}'
+prompt_segment:4> [[ NONE != NONE ]]
+prompt_segment:7> echo -n '%{%K{black}%}%{%F{default}%} '
+prompt_segment:9> CURRENT_BG=black
+prompt_segment:10> [[ -n '%(!.%{%F{yellow}%}.)DS#%m' ]]
+prompt_segment:10> echo -n '%(!.%{%F{yellow}%}.)DS#%m'
+build_prompt:5> prompt_dir
+prompt_dir:1> prompt_segment blue black '%~'
+prompt_segment:1> local bg fg
+prompt_segment:2> [[ -n blue ]]
+prompt_segment:2> bg='%K{blue}'
+prompt_segment:3> [[ -n black ]]
+prompt_segment:3> fg='%F{black}'
+prompt_segment:4> [[ black != NONE && blue != black ]]
+prompt_segment:5> echo -n ' %{%K{blue}%F{black}%}%{%F{black}%} '
+prompt_segment:9> CURRENT_BG=blue
+prompt_segment:10> [[ -n '%~' ]]
+prompt_segment:10> echo -n '%~'
+build_prompt:6> prompt_git
+prompt_git:1> (( 1 ))
+prompt_git:2> local PL_BRANCH_CHAR
+prompt_git:3> '(anon)'
+(anon):1> local 'LC_ALL=' 'LC_CTYPE=en_US.UTF-8'
+(anon):2> PL_BRANCH_CHAR=
+prompt_git:7> local ref dirty mode repo_path
+prompt_git:8> repo_path=+prompt_git:8> git rev-parse --git-dir
+prompt_git:8> repo_path=''
+prompt_git:10> git rev-parse --is-inside-work-tree
+build_prompt:7> prompt_bzr
+prompt_bzr:1> (( 0 ))
+prompt_bzr:1> return
+build_prompt:8> prompt_hg
+prompt_hg:1> (( 0 ))
+prompt_hg:1> return
+build_prompt:9> prompt_end
+prompt_end:1> [[ -n blue ]]
+prompt_end:2> echo -n ' %{%k%F{blue}%}'
+prompt_end:6> echo -n '%{%f%}'
+prompt_end:7> CURRENT_BG='
The problem was kaspersky program :(
I did not matter with pyenv and zsh

Repeat printf arguments with command line operators

I want to repeat the same argument $i for the instances 03-12. I'm really trying to use some nco operators - but the printf statement is hanging me up.
I'm trying to use an netcdf operator on it - where these outputs of the printf are the input files to the command. While this works now with the printf statements, it's not piping into the netcdf command. Which goes as: ncea -v T,U inputfiles outputfile
#!/bin/csh
set i = 1
while ($i < 2)
ncea -v T,U
foreach j ( {3,4,6,7,8,9,10,11,12} )
`printf O3_BDBP_1979ghg.cam.h0.00%02d-%02d.nc $j $i `
end
O3_BDBP_1979.nc
# i = $i + 1
end
Other printf statements I've tried are
ncea -v T,U `printf O3_BDBP_1979ghg.cam.h0.00{03,04,05,06,07,08,09,10,11,12}-%02d.nc $i` O3_BDBP_1979.nc
ncea -v T,U `printf O3_BDBP_1979ghg.cam.h0.00{03,04,05,06,07,08,09,10,11,12}-%1$02d.nc $i` O3_BDBP_1979.nc