What I want to do: Start my script with a list of files as arguments. From within my script I want to start xterm that starts mplayer with these files.I tried several things. I call my script like this:myscript.sh *The files are named likeaaa AAAbbb BBBccc DDD(i.e. filenames with spaces) and are playable sounds, music or videos with mplayer.This is what I triedAll of the following commands were written inside my script!I tried:The following works. Files are printed.ls -l $@The following works. Files are printed.IFS='\n'ls -l $*The following works. Files are printed. Strangely I do not need the IFS='\n' here. Why?xterm -e 'ls -l $*; read'This does not find the files. FILES=$@ls -l $FILESThis does not find the files. Here all filenames are treated as one long filename. (???)IFS='\n'FILES=$@ls -l $FILESThis does not find the files. export FILES=$@ls -l $FILESBut the following works. Files are printed.IFS='\n'export FILES=$@ls -l $FILESNow with mplayer.This works.IFS='\n'export FILES=$@mplayer $FILESThis does not work. But why does number 2 for ls -l work then? Here mplayer exits printing its help as if I just start mplayer with no arguments.xterm -e 'mplayer $*; read'This does not work. It fails for all the files with spaces in the filename.IFS='\n'FILES=$@xterm -e 'mplayer $FILES; read'Question: How can I start mplayer from its own xterm with the files saved in the $FILES variable?
how to start from within my shell-script xterm which starts mplayer and plays the files that are the argument of the script
bash;shell script;mplayer
If you want to pass the arguments to your script to mplayer, in an xterm, this should work:#!/bin/shxterm -e mplayer $@This works because of how $@ expands: one parameter per item. xterm does not attempt to interpret the arguments to the command in any way; it just passes them through.If you need actually put your file list in a variable, your best bet is to use an array variable. For example:#!/bin/bashdeclare -a FILESfor f; do    if [ -r $f ]; then        FILES+=($f)    fidonexterm -e mplayer ${FILES[@]}The above filters the files to only pass ones which are readable. This is just an example, normally you'd not do this type of filtering. Also, typically, I'd use a lowercase variable name, unless I were planning on exporting it.PS: Depending on what you're doing, are you aware of mplayer's -slave mode?