Hello, less(1) fails to write its buffer to pathnames with environment variables or the tilda home directory shortcut in them. The following patch corrects this by using the shell to glob filenames with lessecho instead of glob(3).
Reproduction instructions: $ echo hi | less hi [type "s~/newfile.txt"] Cannot write to "~/newfile.txt" (press RETURN) $ echo hi | less hi [type "s$HOME/ksh.patch"] Cannot write to "$HOME/ksh.patch" (press RETURN) Index: Makefile.in =================================================================== RCS file: /cvs/src/usr.bin/less/Makefile.in,v retrieving revision 1.9 diff -u Makefile.in --- Makefile.in 16 Apr 2003 19:10:09 -0000 1.9 +++ Makefile.in 28 Mar 2010 03:11:52 -0000 @@ -48,7 +48,7 @@ output.${O} position.${O} prompt.${O} search.${O} signal.${O} \ tags.${O} ttyin.${O} version.${O} @REGEX_O@ -all: less lesskey +all: less lesskey lessecho less: ${OBJ} ${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS} @@ -56,6 +56,9 @@ lesskey: lesskey.${O} version.${O} ${CC} ${LDFLAGS} -o $@ lesskey.${O} version.${O} +lessecho: lessecho.${O} version.${O} + ${CC} ${LDFLAGS} -o $@ lessecho.${O} version.${O} + ${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h filename.${O}: ${srcdir}/filename.c @@ -67,6 +70,7 @@ install: all ${INSTALL_PROGRAM} less ${bindir}/${binprefix}less ${INSTALL_PROGRAM} lesskey ${bindir}/${binprefix}lesskey + ${INSTALL_PROGRAM} lessecho ${bindir}/${binprefix}lessecho install-strip: ${MAKE} INSTALL_PROGRAM='${INSTALL_PROGRAM} -s' install Index: lglob.h =================================================================== RCS file: /cvs/src/usr.bin/less/lglob.h,v retrieving revision 1.3 diff -u lglob.h --- lglob.h 22 Apr 2003 22:57:13 -0000 1.3 +++ lglob.h 28 Mar 2010 03:12:12 -0000 @@ -25,7 +25,9 @@ #include <glob.h> #define GLOB_FLAGS (GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE) +#if 0 #define DECL_GLOB_LIST(list) glob_t list; int i; +#endif #define GLOB_LIST(filename,list) glob(filename,GLOB_FLAGS,0,&list) #define GLOB_LIST_FAILED(list) 0 #define SCAN_GLOB_LIST(list,p) i = 0; i < list.gl_pathc; i++