[ https://issues.apache.org/jira/browse/KAFKA-4566?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15831442#comment-15831442 ]
Akhilesh Naidu edited comment on KAFKA-4566 at 1/20/17 9:16 AM: ---------------------------------------------------------------- One approach could be to simulate the working of the readlink function, in a portable manner. below is the code snippet {code:title=Example.sh|borderStyle=solid} # Function to get target file in case of symlinks GetTargetFile () { FILE=$0 cd `dirname $FILE` FILE=`basename $FILE` # Iterate down a chain of symlinks while [ -L "$FILE" ] do FILE=`readlink $FILE` cd `dirname $FILE` FILE=`basename $FILE` done # Append the file to the present directory, # to get the canonicalized name. FILE=`pwd -P`/$FILE echo $FILE } exec $(dirname $(GetTargetFile $0))/kafka-run-class.sh kafka.tools.ConsoleConsumer "$@" {code} have tested this on 1) MacOS (system details):- bash -version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15) Copyright (C) 2007 Free Software Foundation, Inc. 2) CentOS release 6.8 (system details):- bash -version GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> was (Author: akhilesh_naidu): One approach could be to simulate the working of the readlink function, in a portable manner. below is the code snippet ------------------------------------------------------ # Function to get target file in case of symlinks GetTargetFile () { FILE=$0 cd `dirname $FILE` FILE=`basename $FILE` # Iterate down a chain of symlinks while [ -L "$FILE" ] do FILE=`readlink $FILE` cd `dirname $FILE` FILE=`basename $FILE` done # Append the file to the present directory, # to get the canonicalized name. FILE=`pwd -P`/$FILE echo $FILE } exec $(dirname $(GetTargetFile $0))/kafka-run-class.sh kafka.tools.ConsoleConsumer "$@" ------------------------------------------------------ have tested this on 1) MacOS (system details):- bash -version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15) Copyright (C) 2007 Free Software Foundation, Inc. 2) CentOS release 6.8 (system details):- bash -version GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> > Can't Symlink to Kafka bins > --------------------------- > > Key: KAFKA-4566 > URL: https://issues.apache.org/jira/browse/KAFKA-4566 > Project: Kafka > Issue Type: Bug > Components: tools > Affects Versions: 0.10.1.1 > Reporter: Stephane Maarek > Labels: newbie > > in the kafka consumer for example, the last line is : > https://github.com/apache/kafka/blob/trunk/bin/kafka-console-consumer.sh#L21 > {code} > exec $(dirname $0)/kafka-run-class.sh kafka.tools.ConsoleConsumer "$@" > {code} > if I create a symlink using > {code} > ln -s > {code} > it doesn't resolve the right directory name because of $(dirname $0) > I believe the right way is to do: > {code} > "$(dirname "$(readlink -e "$0")")" > {code} > > Any thoughts on that before I do a PR? -- This message was sent by Atlassian JIRA (v6.3.4#6332)