Copy-pasted code behaves diffrent


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy-pasted code behaves diffrent
# 1  
Old 12-08-2014
Copy-pasted code behaves diffrent

Heyas

I'm currently attempting to apply the code of tui-select to tui-list.
That is because tui-list simply made a 1 string list, while tui-select uses dynamicly up to 3 strings per line.

Anyway, so i copy pasted the code, and just made the changes marked with red....
Know that both scripts have ARGS=("${@}")

Code:
	unset OUT[@]
	MAX=3
	CUR=0
	DONE=0
	for OPT in "${ARGS[@]}"
	do	DONE=$((DONE+1))
		case $MODE in
		num)	count=$DONE	;;
		alpha)	count=$(num2char $DONE)	;;
		roman)	count=$(num2roman $DONE)	;;
		esac
		
		if [[ $CUR -lt $MAX ]]
		then	len=0
			for O in "${OUT[@]}";do len=$[ $len + ${#O} ];done
			ID="$count)"
			sum=$[ $len + ( ${#BORDER_LEFT} * 2 ) + 2 + ${#ID} + 1 ]
			if [[ $sum -lt $COLUMNS ]]
			then	OUT[$CUR]="$ID $OPT"
				shown=false
				CUR=$(( $CUR + 1 ))
			else	tui-echo "${OUT[0]}" "${OUT[1]}" "${OUT[2]}" >> /dev/stderr  
				shown=true
			fi
		fi
		if [[ $CUR -eq $MAX ]]
		then 	tui-echo "${OUT[0]}" "${OUT[1]}" "${OUT[2]}" >> /dev/stderr  
			shown=true
		fi
		#counter=$(( $counter + 1 ))
		$shown && CUR=0 && unset OUT[@]
	done
	# Print unprinted
	! $shown && tui-echo "${OUT[@]}" >> /dev/stderr

So given this little change, i would expect pretty much the same output:
But its not..
Code:
# But now i get this:
:) ~/prjs/tui/bin $ ./tui-list a b c
# |                                                                                                              | #
# |                                                                                                              | #
# |                                                                                                              | #

# Instead of what i expect from the 'source': (without the 2nd line)
:( ~/prjs/tui/bin $ ./tui-select a b c
# | 1) a                                                2) b                                                3) c | #
# | >


Sure, the original code still works (if i'd uncomment it, $C handling is already replaced by $DONE)...
Code:
#	C=0
#	while [[ ! "" = "${ARGS[$C]}" ]];do
	#	case $MODE in
	#	num)	count=$DONE	;;
	#	alpha)	count=$(num2char $DONE)	;;
	#	roman)	count=$(num2roman $DONE)	;;
	#	esac
#		tui-echo "$count) ${ARGS[$C]}"
#		C=$((C+1))
#	done

But it only used the left algiment, while there could be a centred and right aligned too...

Any ideas please?

---------- Post updated at 17:02 ---------- Previous update was at 16:41 ----------

Me gringo... COLUMS was empty...
/solved
# 2  
Old 12-17-2014
Looks unbalanced: ID="$count)"
# 3  
Old 12-17-2014
He's trying to make a list like:

Code:
I) Accounts
II) Finance
III) Legal
IV) Payroll

This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

'Connect' behaves differently on Solaris 11

Our application fails to run successfully on Solaris 11. The same works fine in Solaris 10. Due to which we are unable to migrate to Solaris 11. The app basically involves forking a child process, which finally connects with parent process. But on Solaris 11, it is unable to connect with parent... (0 Replies)
Discussion started by: wini008
0 Replies

2. Shell Programming and Scripting

Grep behaves diffrent upon printf or echo output

Hello I want to check whether certain arguments were passed to the script, and when those are, not doing a log entry. If those arguments are not passed, always do a log entry (*new call*). What currently i have is this: echo "${@}"|grep -q \\- || \ tui-log -e "$LOG" "\r---- New call $$... (4 Replies)
Discussion started by: sea
4 Replies

3. UNIX for Dummies Questions & Answers

Is there a limit in number of lines to be Copy pasted in VI editor ?

In my old shop, we only had AIX machines there (all of version 6.1 ). FTP ports were not open for these AIX machines because of some security thing. So, we can't ftp scripts in ASCII mode. When we wanted to copy huge scripts (shell scripts, sql scripts , ..etc) from our Windows based laptop... (6 Replies)
Discussion started by: kraljic
6 Replies

4. Linux

Does a network switch behaves as webserver

Hi, I have a question on web servers and network switches. Why a network switch should support certificate management, that means generating public and private keys... installing a certificate etcetra. Regards Chaitanya. :b: (4 Replies)
Discussion started by: chaitus.28
4 Replies

5. Shell Programming and Scripting

why Cron behaves different ?

Hi, i have script called script.ksh script.ksh --------- echo "Narayana" >$HOME/script.log echo "$0" |sed 's/.ksh//' >>$HOME/script.log My question is: -------------- when iam executing on the prompt it is giving good results what we have expected... example on the prompt:... (4 Replies)
Discussion started by: lnviyyapu
4 Replies

6. Shell Programming and Scripting

su - user -c 'command' behaves differently

I notice that su - user (note with dash) brings in more of the user's environment than does su - user -c 'command'. For example, if root does an su - user, and types "umask" to the prompt, one umask is displayed; yet, if instead the command is su - user -c 'umask', the value is different. I thought... (2 Replies)
Discussion started by: drokerm
2 Replies

7. AIX

Command behaves different in script and on prompt

$cat /tmp/tuxob.lst udi ***** jim 10 ant 19 ibm ***** $ input=`head -1 /tmp/tuxob.lst | awk '{print $NF}'` $ echo $input The output I am expecting is '*****'. But It is showing me the available files of current directory. When I run the command head -1 /tmp/tuxob.lst | awk '{print $NF} ... (3 Replies)
Discussion started by: panchpan
3 Replies

8. Shell Programming and Scripting

mpack behaves abnormally

Hi, I was using mpack to send mails using cronjob with attachments. It was working perfect. But recently it's behaving strangely. Its sending the mails without any error message but the mail is not getting delivered. The code I was using: /usr/local/bin/mpack -s "$SUBJECT" -d $MSGBODY... (0 Replies)
Discussion started by: itesh.dash
0 Replies

9. Programming

using a filepointer in a diffrent program

Hi ALL : consider the given 2 codes: //p1.c #include<stdio.h> FILE * fp; main() { pid_t pid; fp=fopen(".........."); // now i am transfering the control to a new process(p2.c). pid=fork(); if(pid==0) ..... execl(" p2".....); .... ... (6 Replies)
Discussion started by: bankpro
6 Replies

10. UNIX for Advanced & Expert Users

Diffrent IP range connectivity

Hi guys, We have different IP ranges in our LAN, for instance my system IP Add. is in 163.183.37.x range, in the meantime i wish to connect to our printer/plotter which is 163.183.4.x & our LAN in another location with 163.183.38.x. What shoul i do except defining pesudo IP Add's? as a... (1 Reply)
Discussion started by: nikk
1 Replies
Login or Register to Ask a Question