why does ls -p give different result for command-line and bash file

107 Views Asked by At

From a bash command line, running ls -ldp on a link to a directory

ls -ldp /var/www/cgi-bin/PLACENAMES

gives

 /var/www/cgi-bin/PLACENAMES -> PLACENAMES-BIGSUR/

with trailing slash as expected.

But using same command in bash script file gives

/var/www/cgi-bin/PLACENAMES -> PLACENAMES-BIGSUR

i.e. without slash

Makes no sense to me. Would like to get useful info the slash provides in my script.

Cannot see anything in man page to cover this.
Running Ubuntu GNU bash, version 5.1.16

Responding to comments here:

bash script file uses #! /bin/usr/bash
I tried changing to #! /bin/bash but no change

script : type ls => ls is /usr/bin/ls
command : type ls => ls is aliased to `/bin/ls --color=auto'

Noting 'ls' difference above, tried specifying both /usr/bin/ls and /bin/ls in script, instead of simple 'ls' I'd been using, both gave the same result (sans end /)

environment has LS_COLORS but no other 'LS' variable

script file results cited come from 'set -vx' output


Script+Output:

!#/usr/bin/bash                                                                                   
set -vx
/usr/bin/ls -lpd /var/www/cgi-bin/PLACENAMES

347 test.ls-p.sh
/usr/bin/ls -ldp /var/www/cgi-bin/PLACENAMES
3 /usr/bin/ls -ldp /var/www/cgi-bin/PLACENAMES
lrwxrwxrwx 1 jack jack 17 Jan 17  2015 /var/www/cgi-bin/PLACENAMES -> PLACENAMES-BIGSUR
0

There are 0 best solutions below