Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 2652  / 1 Year ago, sat, february 11, 2023, 5:16:49

So the script is:



#!/bin/bash

for line in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
if [[ "$line" = "" || "$line" = " " ]]; then
exit
else
unzip "$line" -d "temp"
fi
done


It works well and unzips the file. But if the file is named with a space (eg: Leon - 1994.zip) it will not work and the $line will be



1st time: /home/citybong/Downloads/Leon



2nd time: -



3rd time: 1994.zip



Edit: I fount a link http://g-scripts.sourceforge.net/faq.php for the question: "My script can't handle multiple files/files with spaces" but i am kinda newbie to bash scripting and i can't understand their solutions


More From » bash

 Answers
4

IFS is by default set to space, that's why your string is being divided into spaces. Just set it to the newline with the following code:



IFS_BAK=$IFS
IFS="
"

for line in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
whatever $line
done

IFS=$IFS_BAK

[#33196] Sunday, February 12, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eballxeye

Total Points: 370
Total Questions: 91
Total Answers: 139

Location: Suriname
Member since Sat, Jan 1, 2022
2 Years ago
;