MutaMestri Posted April 23, 2020 Report Posted April 23, 2020 DB Unix Experts , Small help please I have variable with bunch of filenames few with spaces and few non-spaces , please see below , when file executing with space , it should take it as it is. Script ===== files=" DKC Lab postcr " for file in $files; do echo "$file" done Output ==== $ sh while.sh DKC ===> Here the output i want to be same as DKC Lab Lab postcr Please help bro Quote
Kumaravaarma Posted April 23, 2020 Report Posted April 23, 2020 Then you should change the script to the below or 1) Files='DKC Lab postcr echo $Files. 2) don't use any script use echo "what you want" 😝. If you have automated process add subject "job completed with no issues" Quote
kumar4world Posted April 23, 2020 Report Posted April 23, 2020 1 hour ago, Kumaravaarma said: Then you should change the script to the below or 1) Files='DKC Lab postcr echo $Files. 2) don't use any script use echo "what you want" 😝. If you have automated process add subject "job completed with no issues" for loop considers "spaces" as a seperator for input. Your file "DKC Lab" has space in it. Can't you just rename such files? Quote
kumar4world Posted April 23, 2020 Report Posted April 23, 2020 11 minutes ago, kumar4world said: for loop considers "spaces" as a seperator for input. Your file "DKC Lab" has space in it. Can't you just rename such files? just add this to your script at the top "IFS=$'\n'" and put all the files in a temp file (temp_file.txt) and run your temp file containing file names: cat temp_file.txt DKC Lab postcr your script: IFS=$'\n' for file in `cat temp_file.txt`; do echo $file;done DKC Lab postcr Quote
Kumaravaarma Posted April 23, 2020 Report Posted April 23, 2020 1 hour ago, kumar4world said: just add this to your script at the top "IFS=$'\n'" and put all the files in a temp file (temp_file.txt) and run your temp file containing file names: cat temp_file.txt DKC Lab postcr your script: IFS=$'\n' for file in `cat temp_file.txt`; do echo $file;done DKC Lab postcr Can you please one with an example for both while and for loop and let how to use the input parameters Quote
SwathiNaidu Posted April 23, 2020 Report Posted April 23, 2020 I am certified cloud specialist buffalo🐃 Quote
SwathiNaidu Posted April 23, 2020 Report Posted April 23, 2020 6 minutes ago, Avenger said: Specialist buffalos kuda vachayi last ki Yes donkey🦓 Quote
kumar4world Posted April 23, 2020 Report Posted April 23, 2020 1 hour ago, Kumaravaarma said: Can you please one with an example for both while and for loop and let how to use the input parameters file: cat temp_file.txt DKC Lab postcr while while read -r LINE ; do echo "${LINE}"; done < temp_file.txt DKC Lab postcr for: IFS=$'\n' for file in `cat temp_file.txt`; do echo $file;done DKC Lab postcr Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.