简体   繁体   中英

Bash assign string to variable and print

This has been driving me mad for the past hour or so. I have four variables, $A , $B , $C , and $D . For simplicity's sake, let's assume that the values in each of those variables is their corresponding letter. I have tried to create a variable to hold a string I'd like to print, like so:

s="${A} failed. ${B} ${C} ${D}"
echo "$s"

I've written a test script exactly like so, and it works perfectly. However, in my actual script, the variables are different.

echo $table_name (prints correctly)
echo $source_count (prints correctly)
echo $disk_size (prints correctly)
echo $hive_count (prints correctly)
s="${table_name} failed. ${source_count} ${disk_size} ${hive_count}" (only prints $disk_size and $hive_count)
echo "$s"

Can anyone think of a reason that $s only seems to store the $disk_size and $hive_count ? Is there any character limit to what can be stored in a variable?

$source_count has a CR at the end. Strip it before using the variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM