0

I read that surrounding command line arguments with single quotes is necessary when the command line argument is a string that contains parentheses. However using single quotes around the following argument to the command echo still causes bash: syntax error near unexpected token('`

$ echo -e 'oy_svpvxtvw_ozrqwowm_vrvwvr\m\mzptsouts vro-rmstzmt-ozrqwowm (sttps://trtsuy.xoo/suzm/vro-rmstzmt-ozrqwowm) rs toow, wovs mot ssow z prvv r.v. rvzptrov prvvrvw ou ozrqwowm urpvs, rmstvzw vro-rmstzmt-ozrqwowm opvms zm vxtvrmzp yrowsvr wrmwow uroo vro tszt prvvrvws tsv ozrqwowm urpv. r wvxrwvw mot to usv zpp otsvr rmstzmt ozrq wowm vrvwvrs prqv vro-rmstzmt ozrqwowm yvxzusv tsvy wo mot prvvrvw ozrqwowm prvv zs tsv ozrqwowm rs wrrttvm yut xoov wrts z pot ou ovvrsvzw rm tsv uoro ou opvmrmt zm vxtvrmzp yrowsvr, yurpwrmt uroo sourxv, ouptrppv wvpvmwvmxrvs vtx. Tsv ompy prvv ozrqwowm prvvrvwvrs r uoumw wvrv rvozrqzypv (sttps://rvozrqzypvzpp.trtsuy.ro/prmux.stop) (r xzm wowmpozw tsv pztvst vvrsrom ou rvozrqzypv uroo tsv wowmpozws svxtrom ou tsv rvozrqzypvzpp wvysrtv tsvm ozy yv rmstzpp usrmt upo yut r wom't tsrmq yurpwrmt uroo sourxv rs zppowvw) zmw trtsuy's ztoo rwv wsrxs rums tsv rvsourxv svzvy vpvxtrom. yvxzusv oost ozrqwowm prvvrvwvrs zrv rmstzmt prvvrvws zs rm vmtvr z xooozmw to prvvrvw ozrqwowm rm z yrowsvr, rmstvzw ou prvv ozrqwowm prvvrvwvrs r wvxrwvw to zvorw tsv ovvrsvzw ou rmstzmt ozrqwowm prvvrvws yy vrvwrmt ozrqwowm urpvs rm tsv tvrormzp wrtsout z tur (r.v. vrvwrmt ozrqwowm uroo tsv tvrormzp) usrmt pzmwox zmw pymx (yots pzmwox zmw pymx zrv rm tsv uvworz rvposrtorrvs) wsrxs zrv vvry prtstwvrtst zmw uzst xoopzrvw to ozrqwowm vrvwvrs tszt opvm z yrowsvr wrmwow, to ozqv usrmt pzmwox zmw pymx vvvm uzstvr uor prvvrvwrmt ozrqwowm rm tsv tvrormzp r ssoupw xrvztv z svppvr ovtsow zs suttvstvw svrv (sttps://umrx.stzxqvxxszmtv.xoo/z/120519) zmw svrv (sttps://tosyourm.xoo/vrvw-ozrqwowm-urpvs-tvrormzp/). r tsrmq tsv $1 srtm wrtsrm tsv ovtsow rm tsv prmqs zyout vrvwrmt ozrqwowm urpvs rm tsv tvrormzp usrmt pzmwox zmw pymx ovzms usv tsv stzmwzrw output, tsv stzmwzrw output rs tsvm svmt (pzssvw) usrmt z prpv to tsv xooozmw pymx wsrxs tsvm rvzws uroo tsv stzmwzrw rmput uroo tsv prpv.\m\mmotv: tszt sttps://trtsuy.xoo/vrsrt1985/owp zmw sttps://yrvtttvrpstrz.xoo/2015/08/21/owpvss-yvttvr-ozrqwowm-rm-tvrormzp/ zrv tvrormzp yzsvw ozrqwowm prvvrvwvrs mot yrowsvr yzsvw rmstzmt ozrqwowm prvvrvwvrs.' > echo_test.txt
bash: syntax error near unexpected token `('

Where as surrounding the same string with double quotes does not cause the same error, instead the standard output of echo is successfully redirected to a file named echo_test.txt:

$ echo -e "oy_svpvxtvw_ozrqwowm_vrvwvr\m\mzptsouts vro-rmstzmt-ozrqwowm (sttps://trtsuy.xoo/suzm/vro-rmstzmt-ozrqwowm) rs toow, wovs mot ssow z prvv r.v. rvzptrov prvvrvw ou ozrqwowm urpvs, rmstvzw vro-rmstzmt-ozrqwowm opvms zm vxtvrmzp yrowsvr wrmwow uroo vro tszt prvvrvws tsv ozrqwowm urpv. r wvxrwvw mot to usv zpp otsvr rmstzmt ozrq wowm vrvwvrs prqv vro-rmstzmt ozrqwowm yvxzusv tsvy wo mot prvvrvw ozrqwowm prvv zs tsv ozrqwowm rs wrrttvm yut xoov wrts z pot ou ovvrsvzw rm tsv uoro ou opvmrmt zm vxtvrmzp yrowsvr, yurpwrmt uroo sourxv, ouptrppv wvpvmwvmxrvs vtx. Tsv ompy prvv ozrqwowm prvvrvwvrs r uoumw wvrv rvozrqzypv (sttps://rvozrqzypvzpp.trtsuy.ro/prmux.stop) (r xzm wowmpozw tsv pztvst vvrsrom ou rvozrqzypv uroo tsv wowmpozws svxtrom ou tsv rvozrqzypvzpp wvysrtv tsvm ozy yv rmstzpp usrmt upo yut r wom't tsrmq yurpwrmt uroo sourxv rs zppowvw) zmw trtsuy's ztoo rwv wsrxs rums tsv rvsourxv svzvy vpvxtrom. yvxzusv oost ozrqwowm prvvrvwvrs zrv rmstzmt prvvrvws zs rm vmtvr z xooozmw to prvvrvw ozrqwowm rm z yrowsvr, rmstvzw ou prvv ozrqwowm prvvrvwvrs r wvxrwvw to zvorw tsv ovvrsvzw ou rmstzmt ozrqwowm prvvrvws yy vrvwrmt ozrqwowm urpvs rm tsv tvrormzp wrtsout z tur (r.v. vrvwrmt ozrqwowm uroo tsv tvrormzp) usrmt pzmwox zmw pymx (yots pzmwox zmw pymx zrv rm tsv uvworz rvposrtorrvs) wsrxs zrv vvry prtstwvrtst zmw uzst xoopzrvw to ozrqwowm vrvwvrs tszt opvm z yrowsvr wrmwow, to ozqv usrmt pzmwox zmw pymx vvvm uzstvr uor prvvrvwrmt ozrqwowm rm tsv tvrormzp r ssoupw xrvztv z svppvr ovtsow zs suttvstvw svrv (sttps://umrx.stzxqvxxszmtv.xoo/z/120519) zmw svrv (sttps://tosyourm.xoo/vrvw-ozrqwowm-urpvs-tvrormzp/). r tsrmq tsv $1 srtm wrtsrm tsv ovtsow rm tsv prmqs zyout vrvwrmt ozrqwowm urpvs rm tsv tvrormzp usrmt pzmwox zmw pymx ovzms usv tsv stzmwzrw output, tsv stzmwzrw output rs tsvm svmt (pzssvw) usrmt z prpv to tsv xooozmw pymx wsrxs tsvm rvzws uroo tsv stzmwzrw rmput uroo tsv prpv.\m\mmotv: tszt sttps://trtsuy.xoo/vrsrt1985/owp zmw sttps://yrvtttvrpstrz.xoo/2015/08/21/owpvss-yvttvr-ozrqwowm-rm-tvrormzp/ zrv tvrormzp yzsvw ozrqwowm prvvrvwvrs mot yrowsvr yzsvw rmstzmt ozrqwowm prvvrvwvrs." > echo_test.txt
  • Aren't single quotes supposed to be a more effective way of protecting special characters (e.g. $, (, *) we don't want the shell to interpret, than double quotes? So why does double quotes protect the above parentheses containing string argument where as single quotes fail?

marked as duplicate by Michael Homer bash May 9 at 20:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Both wom't and trtsuy's have apostrophes in them. – Michael Homer May 9 at 20:33