python - Modify string in bash to contain new line character? -
i using bash script call google-api's upload_video.py (https://developers.google.com/youtube/v3/guides/uploading_a_video )
i have mp4 called output.mp4 upload.
the problem cannot array work how like.
this new line character "required" because arguments python script contain spaces.
here simplified version of bash script:
# operator may change these hold=100 location="foo, montana " declare -a file_array=("unique_id_0" "unique_id_1") upload_file=upload_file.txt upload_movie=output.mp4 # hit enter @ end b/c \n not recognized upload_title=$location' - '${file_array[0]}' - hold '$hold' sweeps ' upload_description='the spectrum recording made in @ '$location'. ' # overwrite 1st call > else apppend >> echo "$upload_title" > $upload_file echo "$upload_description" >> $upload_file # load each line of text file array ifs=$'\n' cmd_google=$(<$upload_file) unset ifs nn=1 in "${cmd_google[@]}" echo "$i" # delete last character: \n #i=${i[-nn]%?} #i=${i: : -nn} #i=${i::${#i}-nn} i=${i%?} #i=${i#"\n"} #i=${i%"\n"} echo "$i" done python upload_video.py --file=$upload_movie --title="${cmd_google[0]}" --description="${cmd_google[1]}"
at first attempted remove new line character, appears enter or \n not working how like, each line not separate. writes title , description 1 line.
how modify bash script recognize newline character?
this simpler making it.
# operator may change these hold=100 location="foo, montana" declare -a file_array=("unique_id_0" "unique_id_1") upload_file=upload_file.txt upload_movie=output.mp4 upload_title="$location - ${file_array[0]} - hold $hold sweeps" upload_description="the spectrum recording made in @ $location." cat <<eof > "$upload_file" $upload_title $upload_description eof # ... readarray -t cmd_google < "$upload_file" python upload_video.py --file="$upload_movie" --title="${cmd_google[0]}" --description="${cmd_google[1]}"
i suspect readarray
command looking for, since of above code creating file assume receiving created.
Comments
Post a Comment