0

my script runs without any errors but does not display the variable values. The output of the screen is two spaced blank lines.

#! /bin/bash

set v1=25
set v2 [format "%c" $v1]

echo "$v1"
echo "$v2"

1 Answer 1

2

set isn't used to set the value of a regular variable; it is used to set the positional parameters.

$ set v1=25
$ echo "$1"
v1=25
$ v1=25
$ echo "$v1"
25

Based on [format "%c" $v1], you appear to be writing a hybrid of Tcl and shell.Abash` equivalent would be

v2=$(printf "\x$(printf '%x' "$v1"))
Sign up to request clarification or add additional context in comments.

2 Comments

Hi chepner, thanks for the input, would it be possible to show a working example of the format command?
bash doesn't really have a simple equivalent to convert an integer into the ASCII character it represents. You may be better off figuring out if you really need to do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.