When running commands in git bash, a lot of extra info is added to the terminal. Why is this and how do I turn this off? Example below of output when enter is pressed:
++ __git_ps1
++ local exit=0
++ local pcmode=no
++ local detached=no
++ local 'ps1pc_start=\u#\h:\w '
++ local 'ps1pc_end=\$ '
++ local 'printf_format= (%s)'
++ case "$#" in
++ printf_format=' (%s)'
++ local ps1_expanded=yes
++ '[' -z '' ']'
++ '[' -z '4.4.12(1)-release' ']'
++ shopt -q promptvars
++ local repo_info rev_parse_exit_code
+++ git rev-parse --git-dir --is-inside-git-dir --is-bare-repository --is-inside-work-tree --short HEAD
++ repo_info=
++ rev_parse_exit_code=128
++ '[' -z '' ']'
++ return 0
Related
We have a number of bash scripts running on our Jenkins server for handling our CI/CD tasks. In these tasks, we import other bash scripts or use the bash login shell for certain commands.
As part of this, we get a ton of useless output in our console. For example, with the login shell, we get tons of reporting of Ruby Version Manage initializing for the shell. Eg:
09:19:51 + for __zsh_like_cd_hook in chpwd "${chpwd_functions[#]}"
09:19:51 + typeset -f __rvm_cd_functions_set
09:19:51 + __rvm_cd_functions_set
09:19:51 + __rvm_do_with_env_before
09:19:51 + [[ -n '' ]]
09:19:51 + [[ -n /usr/local/rvm ]]
09:19:51 + source /usr/local/rvm/scripts/initialize
09:19:51 ++ [[ -n 5.0.17(1)-release ]]
09:19:51 ++ shopt -s extglob
09:19:51 ++ (( 0 == 1 ))
09:19:51 ++ export __rvm_env_loaded
09:19:51 ++ : __rvm_env_loaded:0:
09:19:51 ++ : __rvm_env_loaded:1:
09:19:51 ++ [[ -z '' ]]
09:19:51 ++ typeset -f __rvm_cleanse_variables
09:19:51 ++ __rvm_cleanse_variables
09:19:51 ++ __rvm_unset_ruby_variables
09:19:51 ++ unset rvm_env_string rvm_ruby_string rvm_ruby_strings rvm_ruby_binary rvm_ruby_gem_home rvm_ruby_gem_path rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_log_path rvm_ruby_major_version rvm_ruby_minor_version rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_repo_branch rvm_ruby_revision rvm_ruby_selected_flag rvm_ruby_tag rvm_ruby_version rvm_head_flag rvm_ruby_package_file rvm_ruby_configure rvm_ruby_name rvm_ruby_url rvm_ruby_global_gems_path rvm_ruby_args rvm_ruby_name rvm_llvm_flag rvm_ruby_repo_tag
09:19:51 ++ __rvm_load_rvmrc
09:19:51 ++ typeset _file
09:19:51 ++ typeset -a rvm_rvmrc_files
09:19:51 ++ (( 0 == 1 ))
09:19:51 ++ [[ -n '' ]]
09:19:51 +++ umask
09:19:51 ++ export rvm_stored_umask=0022
09:19:51 ++ rvm_stored_umask=0022
09:19:51 ++ rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
09:19:51 ++ [[ -n /usr/local ]]
09:19:51 ++ [[ /var/lib/jenkins/.rvmrc -ef /usr/local/.rvmrc ]]
09:19:51 ++ rvm_rvmrc_files+=("${rvm_prefix}/.rvmrc")
09:19:51 ++ for _file in "${rvm_rvmrc_files[#]}"
09:19:51 ++ [[ -s /etc/rvmrc ]]
09:19:51 ++ __rvm_grep '^\s*rvm .*$' /etc/rvmrc
...
Is there any way to silence this information so we have cleaner console output?
So I got this bash script that perform a backup command from remote server, each server hostname is defined on file called /tmp/quarantine.list. The content is like this:
server1
server2
server1 and server2 is an ssh alias to my remote server, so if I need to access either of them I just run e.g. ssh server1.
I need to backup each server in /tmp/quarantine.list, so I loop each line using while loop. Here is my code.
# Reading from /tmp/quarantine.list
while IFS= read -r list; do
if [ "$list" == "server4" ]; then
users="adminjoe"
fi
tempfile="${logdir}/rsync_$list.log"
SECONDS=0
set +x
if rsync -ca --stats --info=progress2 --remove-source-files $list:/home/${users}/backup/20* $backup_location/$list >> $tempfile 2>&1; then
ssh $list "find /home/${users}/backup/20* -type d -empty -delete"
else
echo "Error while running rsync"
exit 1
fi
set -x
elapsed_time=$SECONDS
transferred_size=$(gawk 'BEGIN { FS=":" } {gsub(/^[ \t]+|[ \t]+$/, "", $2)} /Total transferred file size/ { print $2 }' $tempfile | tr -cd "[:digit:]")
echo "Backup of $list done at $(/bin/date +'%Y-%m-%d_%H:%M:%S') --> $(bytesToHumanReadable $transferred_size)" | tee -a "${HOME}/backup.log"
echo "<b>$list --> $(bytesToHumanReadable $transferred_size)</b>" >> $konten
echo "$transferred_size $list" >> $summaryfile_size
echo "$elapsed_time $list" >> $summaryfile_time
done < "/tmp/quarantine.list"
rm "/tmp/quarantine.list"
The problem is my script only pick the first line of /tmp/quarantine.list, so for example if there was two remote in quarantine.
server2
server6
The script only process server2, while server6 remains untouched. What's weird is, when I put --dry-run option to rsync, it will process all line in /tmp/quarantine.list without problem !
Without --dry-run
+ echo 'Backup of server2 done at 2021-10-28_16:55:26 --> 3.28 GB'
Backup of server2 done at 2021-10-28_16:55:26 --> 3.28 GB
++ bytesToHumanReadable 3280769140
++ S=("bytes" "kB" "MB" "GB" "TB" "PB" "EB" "YB" "ZB")
++ local i=3280769140 d= s=0 S
++ (( i > 1000 && s < 9-1 ))
++ printf -v d .%02d 14
++ i=3280769
++ s=1
++ (( i > 1000 && s < 9-1 ))
++ printf -v d .%02d 76
++ i=3280
++ s=2
++ (( i > 1000 && s < 9-1 ))
++ printf -v d .%02d 28
++ i=3
++ s=3
++ (( i > 1000 && s < 9-1 ))
++ echo '3.28 GB'
+ echo '<b>server2 --> 3.28 GB</b>'
+ echo '3280769140 server2'
+ echo '1883 server2'
+ IFS=
+ read -r list
+ rm /tmp/quarantine.list
With --dry-run
+ echo 'Backup of server2 done at 2021-10-28_16:07:14 --> 3.28 GB'
Backup of server2 done at 2021-10-28_16:07:14 --> 3.28 GB
++ bytesToHumanReadable 3280769140
++ S=("bytes" "kB" "MB" "GB" "TB" "PB" "EB" "YB" "ZB")
++ local i=3280769140 d= s=0 S
++ (( i > 1000 && s < 9-1 ))
++ printf -v d .%02d 14
++ i=3280769
++ s=1
++ (( i > 1000 && s < 9-1 ))
++ printf -v d .%02d 76
++ i=3280
++ s=2
++ (( i > 1000 && s < 9-1 ))
++ printf -v d .%02d 28
++ i=3
++ s=3
++ (( i > 1000 && s < 9-1 ))
++ echo '3.28 GB'
+ echo '<b>server2 --> 3.28 GB</b>'
+ echo '3280769140 server2'
+ echo '32 server2'
+ IFS=
+ read -r list
+ '[' server6 == server4 ']'
As you can see, the latter continues with server6 as opposed of the former. I just wondering what I'd do wrong here?
This can happen if the last line of the file does not end with a newline. Then read will actually read the line, but it will return a non-zero status (ref: https://www.gnu.org/software/bash/manual/bash.html#index-read). This non-zero status causes the while loop to end.
The idiomatic way to handle this is:
while IFS= read -r list || [[ -n $list ]]; do
I am currently testing a bash script to perform database migration.
The scripts basically accepts some parameters such as:
the name of the database to migrate
the server from which migrate it
the server to which migrate it
In the script there is a function which "builds" the mysql and mysqldump commands to be executed, depending on whether the server from/to is local/remote.
the function build_mysql_command is then used like this:
_query="$(build_mysql_command mysql from)"
_dump="$(build_mysql_command mysqldump from)"
_restore="$(build_mysql_command mysql to)"
However, when the function build_mysql_command has to call open_ssh_tunnel, it hangs on the last instruction, as I have tested by using the script with the -x switch.
If instead I put the SSH tunnel opening outside build_mysql_command, and remove the call from there, it works.
However, I do not think I made any mistake in the above functions, so I do not understand why the script would hang.
Here is a very stripped down example which shows the problem, where I replaced the actual IP address of the remote server with 1.2.3.4:
#!/bin/bash
set -x
set -o pipefail
# $1 = 'from' or 'to'
get_local_port() {
case "$1" in
from)
echo 30303
;;
to)
echo 31313
;;
*)
echo 0
;;
esac
}
# $1 = 'from' or 'to'
build_ssh_command() {
local _ssh="ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no"
if [ ! -z "${params[password-$1]}" ] ; then
_ssh="sshpass -f ${params[password-$1]} $_ssh"
fi
echo "$_ssh"
}
# $1 = 'from' or 'to'
open_ssh_tunnel() {
# se non già aperto
if [ -z "${cleanup[ssh-tunnel-$1]}" ] ; then
local _port="$(get_local_port "$1")"
local _ssh="$(build_ssh_command "$1")"
local _pregp="fnNTL $_port:localhost:3306 ${params[migrate-$1]}"
local _command="$_ssh -$_pregp"
# tento apertura tunnel SSH
if ! $_command ; then
return 1
else
# salvo PID del tunnel così aperto
local _pid="$(pgrep -f "$_pregp" 2> /dev/null)"
if [ -z "$_pid" ] ; then
return 1
fi
cleanup["ssh-tunnel-$1"]="$_pid"
fi
fi
return 0
}
# verifica se un indirizzo fa riferimento alla macchina locale
# $1 = indirizzo da verificare
is_local_address() {
local _host="$(hostname)"
case "$1" in
localhost|"127.0.0.1"|"$_host")
return 0
;;
*)
return 1
;;
esac
}
# costruisce un comando di dump o restore MySQL
# $1 = comando di base
# $2 = tipo server ('from' o 'to')
build_mysql_command() {
local _command="$1 --user=root --password=xxx"
if is_local_address "${params[migrate-$2]}" ; then
# connessione tramite socket
_command="$_command --protocol=socket --socket=/opt/agews64/data/mysql/mysql.sock"
elif open_ssh_tunnel "$2" ; then
# altrimenti uso connessione tramite tunnel SSH
_command="$_command --protocol=tcp --host=localhost --port=$(get_local_port "$2")"
else
_command=""
fi
echo "$_command"
}
# parametri di esecuzione dello script
declare -A params=(
["migrate-from"]="localhost"
["migrate-to"]="1.2.3.4"
)
_query="$(build_mysql_command "mysql" "from")"
echo "_query = $_query"
_dump="$(build_mysql_command "mysqldump" "to")"
echo "_dump = $_dump"
# fine test
and here is the output when run:
+ set -o pipefail
+ params=(["migrate-from"]="localhost" ["migrate-to"]="1.2.3.4")
+ declare -A params
++ build_mysql_command mysql from
++ local '_command=mysql --user=root --password=xxx'
++ is_local_address localhost
+++ hostname
++ local _host=my.host.name
++ case "$1" in
++ return 0
++ _command='mysql --user=root --password=xxx --protocol=socket --socket=/opt/agews64/data/mysql/mysql.sock'
++ echo 'mysql --user=root --password=xxx --protocol=socket --socket=/opt/agews64/data/mysql/mysql.sock'
+ _query='mysql --user=root --password=xxx --protocol=socket --socket=/opt/agews64/data/mysql/mysql.sock'
+ echo '_query = mysql --user=root --password=xxx --protocol=socket --socket=/opt/agews64/data/mysql/mysql.sock'
_query = mysql --user=root --password=xxx --protocol=socket --socket=/opt/agews64/data/mysql/mysql.sock
++ build_mysql_command mysqldump to
++ local '_command=mysqldump --user=root --password=xxx'
++ is_local_address 1.2.3.4
+++ hostname
++ local _host=asp10.626suite-online.it
++ case "$1" in
++ return 1
++ open_ssh_tunnel to
++ '[' -z '' ']'
+++ get_local_port to
+++ case "$1" in
+++ echo 31313
++ local _port=31313
+++ build_ssh_command to
+++ local '_ssh=ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no'
+++ '[' '!' -z '' ']'
+++ echo 'ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no'
++ local '_ssh=ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no'
++ local '_pregp=fnNTL 31313:localhost:3306 1.2.3.4'
++ local '_command=ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -fnNTL 31313:localhost:3306 1.2.3.4'
++ ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -fnNTL 31313:localhost:3306 1.2.3.4
Warning: Permanently added '1.2.3.4' (ECDSA) to the list of known hosts.
+++ pgrep -f 'fnNTL 31313:localhost:3306 1.2.3.4'
++ local _pid=8919
++ '[' -z 8919 ']'
++ cleanup["ssh-tunnel-$1"]=8919
++ return 0
+++ get_local_port to
+++ case "$1" in
+++ echo 31313
++ _command='mysqldump --user=root --password=xxx --protocol=tcp --host=localhost --port=31313'
++ echo 'mysqldump --user=root --password=xxx --protocol=tcp --host=localhost --port=31313'
As you can see, the script hangs at the very last line of build_mysql_command when it has opened the SSH tunnel to the remote server, but shows no problem when it builds the local command.
I am trying to source an auto-completion script as a non-root user but receive a 'Bad Substitution' error message.
I am able to source it as root though.
On a other server I am able to source the script as non-root user.
I am guessing it is not a permission issue since I receive the same error trying to source a copy of the script with full permissions.
I have tried to echo all the environment variables used in the script, no issue there.
As the auto-completion script is packaged with the software I use I would rather not modify it.
Anyone would have a hint on what could be missing to the user so I can source the script from it ?
Thanks in advance for any idea!
Edit1:
ps output:
PID TTY TIME CMD
3261 pts/0 00:00:00 bash
73620 pts/0 00:00:00 ps
Error only as non-root user:
/opt/splunk/share/splunk/cli-command-completion.sh: 7: /opt/splunk/share/splunk/cli-command-completion.sh: Bad substitution
Script:
# Vainstein K 12aug2013
# # # Check a few prereqs.
feature='"splunk <verb> <object>" tab-completion'
[ `basename $SHELL` != 'bash' ] && echo "Sorry, $feature is only for bash" >&2 && return 11
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
[ `type -t complete` != 'builtin' ] && echo "Sorry, $feature requires a bash that supports programmable command completion" >&2 && return 13
die () {
echo "(exit=$?) $#" >&2 && exit 42
}
ifSourced () { # do NOT exit(1) from this function!
local readonly tempfile=`pwd`/tmp--cli-completion--$$
rm -f $tempfile
$BASH ${BASH_ARGV[0]} --populateTempfile $tempfile
[ $? -eq 0 ] || return
[ -e $tempfile ] || return
. $tempfile
rm -f $tempfile
# # # Associate the completion function with the splunk binary.
local readonly completionFunction=fSplunkComplete
complete -r splunk 2>/dev/null
complete -F $completionFunction splunk
# You can view the completion function anytime via: $ type fSplunkComplete
}
ifInvoked () { # all error checking happens in this function
local readonly debug=false
local readonly tempfile=$1
$debug && echo "Told that tempfile=$tempfile"
# # # If anything goes wrong, at least we don't pollute cwd with our tempfile.
$debug || trap "rm -f $tempfile" SIGINT SIGQUIT SIGTERM SIGABRT SIGPIPE
touch $tempfile || die "Cannot touch tempfile=$tempfile"
# # # Decide where SPLUNK_HOME is.
if [ "$(dirname $(pwd))" == 'bin' ]; then
local readonly splunkHome=$(dirname $(dirname $(pwd)))
elif [ -n "$SPLUNK_HOME" ]; then
local readonly splunkHome=$SPLUNK_HOME
else
die 'Cannot figure out where SPLUNK_HOME is'
fi
$debug && echo "Decided SPLUNK_HOME=$splunkHome"
# # # Check that splunk (the binary) exists.
local readonly splunkBinary=$splunkHome/bin/splunk
[ -e $splunkBinary -a -x $splunkBinary ] || die "Cannot find expected binary=$splunkBinary"
# # # Find the file with object->{verb1,verb2,...} map.
local readonly splunkrcCmdsXml=$splunkHome/etc/system/static/splunkrc_cmds.xml
[ -e $splunkrcCmdsXml ] || die "Cannot find expected file $splunkrcCmdsXml"
$debug && echo "Shall read verb-obj info from: $splunkrcCmdsXml"
# # # Parse the map file, and generate our internal verb->{objA,objB,...} map.
local -A verb_to_objects
local line object verb objectsForThisVerb lineNumber=0
local inItem=false
local readonly regex_depr='\<depr\>'
local readonly regex_verb='\<verb\>'
local readonly regex_synonym='\<synonym\>'
while read line; do
lineNumber=$((lineNumber+1))
if $inItem; then
if [[ $line =~ '</item>' ]]; then
$debug && echo "Exited item tag at line=$lineNumber; this was obj=$object"
inItem=false
object=''
elif [[ $line =~ '<cmd name' && ! $line =~ $regex_depr && ! $line =~ $regex_synonym ]]; then
[ -z "$object" ] && die "BUG: No object within item tag. (At line $lineNumber of $splunkrcCmdsXml)"
verb=${line#*\"} # remove shortest match of .*" from the front
verb=${verb%%\"*} # remove longest match of ".* from the back
[ "$verb" == '_internal' ] && continue # Why the... eh, moving on.
objectsForThisVerb=${verb_to_objects[$verb]}
objectsForThisVerb="$objectsForThisVerb $object"
verb_to_objects[$verb]=$objectsForThisVerb
$debug && echo "Mapped object=$object to verb=$verb at line=$lineNumber; now objectsForThisVerb='$objectsForThisVerb'"
fi
else # ! inItem
if [[ $line =~ '<item obj' && ! $line =~ $regex_depr && ! $line =~ $regex_verb && ! $line =~ $regex_synonym ]]; then
inItem=true
object=${line#*\"} # remove shortest match of .*" from the front
object=${object%%\"*} # remove longest match of ".* from the back
$debug && echo "Entered item tag at line=$lineNumber, parsed object=$object"
[ "$object" == 'on' ] && inItem=false # Do not expose Amrit's puerile jest.
[ "$object" == 'help' ] && inItem=false # Although 'help' is a verb, splunkrc_cmds.xml constructs it as an object; ugh. We'll deal with the objects (topics) of 'splunk help' separately, below.
fi
fi
done < $splunkrcCmdsXml
$debug && echo "Processed $lineNumber lines. Map keys: ${!verb_to_objects[*]}, values: ${verb_to_objects[#]}"
# # # Oh wait, '<verb> deploy-server' aren't in splunkrc_cmds.xml; thanks, Jojy!!!!!
for verb in reload enable disable display; do
objectsForThisVerb=${verb_to_objects[$verb]}
objectsForThisVerb="$objectsForThisVerb deploy-server"
verb_to_objects[$verb]=$objectsForThisVerb
done
# # # Find the file with topics understood by 'splunk help <topic>' command, and extract list of topics.
local readonly literalsPy=$splunkHome/lib/python2.7/site-packages/splunk/clilib/literals.py
[ -e $literalsPy ] || die "Cannot find expected file $literalsPy"
$debug && echo "Shall read help topics list from: $literalsPy"
local readonly helpTopics=$(sed '/^addHelp/! d; s/^addHelp//; s/,.*$//; s/[^a-zA-Z_-]/ /g; s/^[ ]*//; s/[ ].*$//; /^$/ d' $literalsPy | sort | uniq)
$debug && echo "Parsed help topics list as: $helpTopics"
#######################################################
# # # Write the completion function to tempfile: BEGIN.
local readonly completionFunction=fSplunkComplete
echo -e 'function '$completionFunction' () {' >> $tempfile
echo -e '\tlocal wordCur=${COMP_WORDS[COMP_CWORD]}' >> $tempfile
echo -e '\tlocal wordPrev=${COMP_WORDS[COMP_CWORD-1]}' >> $tempfile
echo -e '\tcase $wordPrev in' >> $tempfile
# # # What can follow 'splunk' itself? Verbs used in main.c to key the 'cmd_handlers' array; and verbs from splunkrc_cmds.xml; and 'help'.
local readonly keys__cmd_handlers='ftr start startnoss stop restart restartss status rebuild train fsck clean-dispatch clean-srtemp validate verifyconfig anonymize find clean createssl juststopit migrate --version -version version httpport soapport spool ftw envvars _RAW_envvars _port_check cmd _rest_xml_dump search dispatch rtsearch livetail _normalizepath _internal logout btool pooling _web_bootstart offline clone-prep-clear-config diag'
local allVerbs="${!verb_to_objects[*]}"
echo -e '\t\tsplunk)\n\t\t\tCOMPREPLY=( $(compgen -W "'$keys__cmd_handlers $allVerbs' help" -- $wordCur) ) ;;' >> $tempfile
# # # What can follow 'splunk _internal'? see cmd_internal() of main.c
local readonly actions_internal='http mgmt https pre-flight-checks check-db call rpc rpc-auth soap-call soap-call-auth prefixcount totalcount check-xml-files first-time-run make-splunkweb-certs-and-var-run-merged'
echo -e '\t\t_internal)\n\t\t\tCOMPREPLY=( $(compgen -W "'$actions_internal'" -- $wordCur) ) ;;' >> $tempfile
# # # Options to 'splunk clean' are in CLI::clean() of src/main/Clean.cpp; to 'splunk fsck', in usageBanner of src/main/Fsck.cpp; to 'splunk migrate', in CLI::migrate() of src/main/Migration.cpp
echo -e '\t\tclean)\n\t\t\tCOMPREPLY=( $(compgen -W "all eventdata globaldata userdata inputdata locks deployment-artifacts raft" -- $wordCur) ) ;;' >> $tempfile
echo -e '\t\tfsck)\n\t\t\tCOMPREPLY=( $(compgen -W "scan repair clear-bloomfilter make-searchable" -- $wordCur) ) ;;' >> $tempfile
echo -e '\t\tmigrate)\n\t\t\tCOMPREPLY=( $(compgen -W "input-records to-modular-inputs rename-cluster-app" -- $wordCur) ) ;;' >> $tempfile
# # # List the help topics.
echo -e '\t\thelp)\n\t\t\tCOMPREPLY=( $(compgen -W "'$helpTopics'" -- $wordCur) ) ;;' >> $tempfile
# # # What can follow 'splunk cmd'? any executable in SPLUNK_HOME/bin/
echo -e '\t\tcmd)\n\t\t\tCOMPREPLY=( $(compgen -o default -o filenames -G "'$splunkHome'/bin/*" -- $wordCur) ) ;;' >> $tempfile
# # # Finally, let each verb be completed by its objects.
for verb in $allVerbs; do
echo -e '\t\t'$verb')\n\t\t\tCOMPREPLY=( $(compgen -W "'${verb_to_objects[$verb]}'" -- $wordCur) ) ;;' >> $tempfile
done
# # # And if we've run out of suggestions, revert to bash's default completion behavior: filename completion.
echo -e '\t\t*)\n\t\t\tCOMPREPLY=( $(compgen -f -- $wordCur) ) ;;' >> $tempfile
echo -e '\tesac' >> $tempfile
echo -e '}' >> $tempfile
$debug && cp $tempfile $tempfile~bak
# # # Write the completion function to tempfile: DONE.
######################################################
# # # Sanity check: source the tempfile, make sure that the function we wrote can be parsed and loaded by the shell.
unset $completionFunction
. $tempfile
[ "`type -t $completionFunction`" == 'function' ] || die 'BUG: generated completion function cannot be parsed by bash'
}
if [ $SHLVL -eq 1 ]; then
[ $# -ge 1 ] && echo "Ignoring supplied arguments: $#" >&2
ifSourced
elif [ $SHLVL -eq 2 ]; then
if [ $# -eq 2 ] && [ $1 == '--populateTempfile' ]; then
ifInvoked $2
else
echo -e "This script must be sourced, like so:\n\n\t\033[1m. $0\033[0m\n"
fi
else
: # user is running screen(1) or something of the sort.
fi
# # # Clean up.
unset die ifSourced ifInvoked
Edit2:
xtrace output
++ feature='"splunk <verb> <object>" tab-completion'
+++ basename /bin/bash
++ '[' bash '!=' bash ']'
++ '[' 4 -lt 4 ']'
+++ type -t complete
++ '[' builtin '!=' builtin ']'
++ '[' 1 -eq 1 ']'
++ '[' 0 -ge 1 ']'
++ ifSourced
+++ pwd
++ local readonly tempfile=/home/splunk/tmp--cli-completion--12431
++ rm -f /home/splunk/tmp--cli-completion--12431
++ /bin/sh cli-command-completion.sh --populateTempfile /home/splunk/tmp--cli-completion--12431
+ feature="splunk <verb> <object>" tab-completion
+ basename /bin/bash
+ [ bash != bash ]
cli-command-completion.sh: 8: cli-command-completion.sh: Bad substitution
++ '[' 2 -eq 0 ']'
++ return
++ unset die ifSourced ifInvoked
Edit3:
When using
set -o verbose
set -o noglob
set -o noglob
and checking differences between OK (root) and failing (non-root) run.
OK side:
[...]
+++ basename /bin/bash
++ '[' bash '!=' bash ']'
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
++ '[' 4 -lt 4 ']'
[...]
++ local readonly tempfile=/home/splunk/tmp--cli-completion--42064
++ rm -f /home/splunk/tmp--cli-completion--42064
++ /bin/bash cli-command-completion.sh --populateTempfile /home/splunk/tmp--cli-completion--42064
+ set -o verbose
set -o noglob
+ set -o noglob
# Vainstein K 12aug2013
[...]
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
+ '[' 4 -lt 4 ']'
[...]
Failing side:
[...]
+++ basename /bin/bash
++ '[' bash '!=' bash ']'
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
++ '[' 4 -lt 4 ']'
[...]
++ local readonly tempfile=/home/splunk/tmp--cli-completion--40686
++ rm -f /home/splunk/tmp--cli-completion--40686
++ /bin/sh cli-command-completion.sh --populateTempfile /home/splunk/tmp--cli-completion--40686
+ set -o verbose
set -o noglob
+ set -o noglob
# Vainstein K 12aug2013
# # # Check a few prereqs.
feature='"splunk <verb> <object>" tab-completion'
+ feature="splunk <verb> <object>" tab-completion
[ `basename $SHELL` != 'bash' ] && echo "Sorry, $feature is only for bash" >&2 && return 11
+ basename /bin/bash
+ [ bash != bash ]
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
cli-command-completion.sh: 10: cli-command-completion.sh: Bad substitution
++ '[' 2 -eq 0 ']'
++ return
# # # Clean up.
unset die ifSourced ifInvoked
++ unset die ifSourced ifInvoked
Seems like as non-root, it runs as /bin/sh whereas as 'bash' as root.
Weird because I tried multiple things to force bash there, maybe not the right ones.
It also fail at line 7 even though the first loop succeeds.
This should do the trick (line 7):
[ $(type -t complete) != 'builtin' ] && echo "Sorry, $feature requires a bash that supports programmable command completion" >&2 && return 13
Turns out from trace output that /bin/sh was used instead of /bin/bash to launch the script because /bin/bash was not set as default shell.
I have changed the default shell to /bin/bash and it is all ok now :)
I have used this method to set /bin/bash as default shell :
Check:
grep /etc/passwd
Change:
chsh --shell /bin/bash
Check modification:
grep /etc/passwd
Thanks for the help!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
When I open terminal I get this error
Is it harming something? How can I fix and get rid of it ?
Last login: Mon Aug 15 11:44:29 on ttys000
-bash: eval: line 33: syntax error: unexpected end of file
As it is suggested by the answer below I should set -x and here is what I did I did set -x
Admins-MBP:~ admin$ set -x
+ set -x
++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=
++ (( i = 0 ))
++ (( i < 12 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 12 ))
++ ch=U
++ [[ U =~ [/._~A-Za-z0-9-] ]]
++ url_path+=U
++ (( ++i ))
++ (( i < 12 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 12 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 12 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 12 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 12 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 12 ))
++ ch=a
++ [[ a =~ [/._~A-Za-z0-9-] ]]
++ url_path+=a
++ (( ++i ))
++ (( i < 12 ))
++ ch=d
++ [[ d =~ [/._~A-Za-z0-9-] ]]
++ url_path+=d
++ (( ++i ))
++ (( i < 12 ))
++ ch=m
++ [[ m =~ [/._~A-Za-z0-9-] ]]
++ url_path+=m
++ (( ++i ))
++ (( i < 12 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 12 ))
++ ch=n
++ [[ n =~ [/._~A-Za-z0-9-] ]]
++ url_path+=n
++ (( ++i ))
++ (( i < 12 ))
++ printf '\e]7;%s\a' file://Admins-MBP/Users/admin
then i did
Admins-MBP:~ admin$ . .bash_profile
+ . .bash_profile
++ '[' -r /Users/admin/.bashrc ']'
++ source /Users/admin/.bashrc
+++ source /Users/admin/perl5/perlbrew/etc/bashrc
++++ export PERLBREW_BASHRC_VERSION=0.76
++++ PERLBREW_BASHRC_VERSION=0.76
++++ export PERLBREW_ROOT=/Users/admin/perl5/perlbrew
++++ PERLBREW_ROOT=/Users/admin/perl5/perlbrew
++++ [[ -z /Users/admin/perl5/perlbrew ]]
++++ [[ -z /Users/admin/.perlbrew ]]
++++ [[ ! -n '' ]]
++++ [[ -f /Users/admin/.perlbrew/init ]]
++++ . /Users/admin/.perlbrew/init
+++++ export PERLBREW_MANPATH=/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man
+++++ PERLBREW_MANPATH=/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man
+++++ export PERLBREW_PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin
+++++ PERLBREW_PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin
+++++ export PERLBREW_PERL=perl-5.16.0
+++++ PERLBREW_PERL=perl-5.16.0
+++++ export PERLBREW_ROOT=/Users/admin/perl5/perlbrew
+++++ PERLBREW_ROOT=/Users/admin/perl5/perlbrew
+++++ export PERLBREW_VERSION=0.74
+++++ PERLBREW_VERSION=0.74
++++ perlbrew_bin_path=/Users/admin/perl5/perlbrew/bin
++++ [[ -f /Users/admin/perl5/perlbrew/bin/perlbrew ]]
++++ perlbrew_command=/Users/admin/perl5/perlbrew/bin/perlbrew
++++ unset perlbrew_bin_path
++++ __perlbrew_activate
+++++ alias perl
++++ [[ -n '' ]]
++++ [[ -n perl-5.16.0 ]]
++++ __perlbrew_set_env perl-5.16.0
++++ local code
+++++ /Users/admin/perl5/perlbrew/bin/perlbrew env perl-5.16.0
++++ code='export PERLBREW_MANPATH="/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man"
export PERLBREW_PATH="/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin"
export PERLBREW_PERL="perl-5.16.0"
export PERLBREW_ROOT="/Users/admin/perl5/perlbrew"
export PERLBREW_VERSION="0.76"'
++++ eval 'export PERLBREW_MANPATH="/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man"
export PERLBREW_PATH="/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin"
export PERLBREW_PERL="perl-5.16.0"
export PERLBREW_ROOT="/Users/admin/perl5/perlbrew"
export PERLBREW_VERSION="0.76"'
+++++ export PERLBREW_MANPATH=/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man
+++++ PERLBREW_MANPATH=/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man
+++++ export PERLBREW_PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin
+++++ PERLBREW_PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin
+++++ export PERLBREW_PERL=perl-5.16.0
+++++ PERLBREW_PERL=perl-5.16.0
+++++ export PERLBREW_ROOT=/Users/admin/perl5/perlbrew
+++++ PERLBREW_ROOT=/Users/admin/perl5/perlbrew
+++++ export PERLBREW_VERSION=0.76
+++++ PERLBREW_VERSION=0.76
++++ __perlbrew_set_path
++++++ manpath
+++++ __perlbrew_purify /Users/admin/perl5/perlbrew/perls/perl-5.16.0/man:/usr/local/share/man:/usr/share/man:/opt/X11/share/man:/Applications/Xcode.app/Contents/Developer/usr/share/man:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man
+++++ local path patharray outsep
+++++ IFS=:
+++++ read -ra patharray
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s /usr/local/share/man
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/usr/share/man
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/opt/X11/share/man
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/Applications/Xcode.app/Contents/Developer/usr/share/man
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man
+++++ outsep=:
++++ export MANPATH=/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man:/usr/local/share/man:/usr/share/man:/opt/X11/share/man:/Applications/Xcode.app/Contents/Developer/usr/share/man:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man
++++ MANPATH=/Users/admin/perl5/perlbrew/perls/perl-5.16.0/man:/usr/local/share/man:/usr/share/man:/opt/X11/share/man:/Applications/Xcode.app/Contents/Developer/usr/share/man:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man
+++++ __perlbrew_purify /Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin
+++++ local path patharray outsep
+++++ IFS=:
+++++ read -ra patharray
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s /Users/admin/.rbenv/shims
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/opt/local/bin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/opt/local/sbin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/usr/local/bin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/usr/bin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/bin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/usr/sbin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/sbin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/opt/X11/bin
+++++ outsep=:
+++++ for path in '"${patharray[#]}"'
+++++ case "$path" in
+++++ printf %s :/Users/admin/.rvm/bin
+++++ outsep=:
++++ export PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin
++++ PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin
++++ hash -r
+++ export PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin:/Users/admin/.rvm/bin
+++ PATH=/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin:/Users/admin/.rvm/bin
++ export PATH=/opt/local/bin:/opt/local/sbin:/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin:/Users/admin/.rvm/bin
++ PATH=/opt/local/bin:/opt/local/sbin:/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin:/Users/admin/.rvm/bin
+++ rbenv init -
++ eval 'export PATH="/Users/admin/.rbenv/shims:${PATH}"
export RBENV_SHELL=bash
source '\''/usr/local/Cellar/rbenv/1.0.0/libexec/../completions/rbenv.bash'\''
command rbenv rehash 2>/dev/null
rbenv() {
local command
command="$1"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
rehash|shell)
eval "$(rbenv "sh-$command" "$#")";;
*)
command rbenv "$command" "$#";;
esac
}source' /Users/admin/perl5/perlbrew/etc/bashrc
+++ export PATH=/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin:/Users/admin/.rvm/bin
+++ PATH=/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/Users/admin/perl5/perlbrew/bin:/Users/admin/perl5/perlbrew/perls/perl-5.16.0/bin:/Users/admin/.rbenv/shims:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/admin/.rvm/bin:/Users/admin/.rvm/bin
+++ export RBENV_SHELL=bash
+++ RBENV_SHELL=bash
+++ source /usr/local/Cellar/rbenv/1.0.0/libexec/../completions/rbenv.bash
++++ complete -F _rbenv rbenv
+++ command rbenv rehash
-bash: eval: line 33: syntax error: unexpected end of file
++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=
++ (( i = 0 ))
++ (( i < 12 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 12 ))
++ ch=U
++ [[ U =~ [/._~A-Za-z0-9-] ]]
++ url_path+=U
++ (( ++i ))
++ (( i < 12 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 12 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i < 12 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i < 12 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i < 12 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i < 12 ))
++ ch=a
++ [[ a =~ [/._~A-Za-z0-9-] ]]
++ url_path+=a
++ (( ++i ))
++ (( i < 12 ))
++ ch=d
++ [[ d =~ [/._~A-Za-z0-9-] ]]
++ url_path+=d
++ (( ++i ))
++ (( i < 12 ))
++ ch=m
++ [[ m =~ [/._~A-Za-z0-9-] ]]
++ url_path+=m
++ (( ++i ))
++ (( i < 12 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i < 12 ))
++ ch=n
++ [[ n =~ [/._~A-Za-z0-9-] ]]
++ url_path+=n
++ (( ++i ))
++ (( i < 12 ))
++ printf '\e]7;%s\a' file://Admins-MBP/Users/admin
Admins-MBP:~ admin$
It's most likely coming from your .bashrc or .bashprofile.
You can try to diagnose the root cause by first using set -x, this will cause your shell to trace all the commands being executed. Then you can source the files again by doing . .bashrc and . bash_profile and see what's going on.