Skip to content

Commit 2bd678c

Browse files
committed
For big data the the read builtin has buffer limitations that can cause it to freeze with very long input strings. Added now an option to read data from file in interactive mode
1 parent 620b19b commit 2bd678c

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

safe_hashes.sh

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,42 @@ EOF
13521352
value="${value_input:-$value}"
13531353
validate_value $value "value"
13541354

1355-
read -rp "Enter the \`data\` (default: $data): " data_input
1356-
data="${data_input:-$data}"
1355+
# Display data separately to avoid terminal buffer issues with large calldata
1356+
echo "Default \`data\` value:"
1357+
echo "How would you like to provide the \`data\`?"
1358+
echo " 1) Use default value shown above (press Enter)"
1359+
echo " 2) Enter/paste data directly"
1360+
echo " 3) Read from a file"
1361+
read -rp "Choose an option (1/2/3): " data_option
1362+
data_option="${data_option:-1}"
1363+
1364+
case "$data_option" in
1365+
1)
1366+
# Use default
1367+
;;
1368+
2)
1369+
echo "Enter the \`data\` (for large data, consider using option 3):"
1370+
# Read without prompt to avoid buffer issues
1371+
IFS= read -r data_input
1372+
if [[ -n "$data_input" ]]; then
1373+
data="$data_input"
1374+
fi
1375+
;;
1376+
3)
1377+
read -rp "Enter the file path containing the data: " data_file
1378+
if [[ -f "$data_file" ]]; then
1379+
# Read the entire file content, removing any whitespace/newlines
1380+
data=$(tr -d '[:space:]' < "$data_file")
1381+
echo "Data loaded from file: ${data:0:66}..." # Show first 66 chars
1382+
else
1383+
echo "${RED}Error: File not found: $data_file${RESET}"
1384+
echo "Using default value instead."
1385+
fi
1386+
;;
1387+
*)
1388+
echo "${YELLOW}Invalid option. Using default value.${RESET}"
1389+
;;
1390+
esac
13571391

13581392
while true; do
13591393
read -rp "Enter the \`operation\` (default: $operation; 0 = CALL, 1 = DELEGATECALL): " operation_input

0 commit comments

Comments
 (0)