bashprintfspecial-characters

printf special character in interactive shell, but not from shell script


I'm trying to print a special character from a Shell script. printf '\U002F' works in interactive shell, but not from Bash shell script. Shell script keeps printing \u002F. I tried to escape \, but it does not work either. Same thing with echo command.


Solution

  • In a RHEL 9.x system I am not able to reproduce an issue.

    bash --version | head -1
    GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)
    
    printf '\u002f'
    /
    
    cat printf.sh
    #! /bin/bash
    echo "$BASH_VERSION"
    printf '\u002f'
    
    ./printf.sh
    5.1.8(1)-release
    /