Skip to content

Instantly share code, notes, and snippets.

Bash Scripting - Quoting

Chiunque abbia usato seriamente la Bash si è scontrato almeno una volta (e probabilmente più di una) con problemi legati al quoting.

Uno dei problemi più comuni è la difficoltà nello script che non riescono a gestire casi in teoria semplici come i file con uno spazio nel nome. Quasi come se fosse impossibile gestire dei file con nomi di quel tipo.

In realtà, anche se quasi nessuno sa come, con la Shell è possibile gestire file con nomi contenenti praticamente qualsiasi cosa. Per come è fatta Bash è possibile lavorare con qualsiasi nome di file che il kernel sia in grado di gestire. Quindi, ammesso di conoscere bene le regole del quoting, si può lavorare con problemi sia con i file con nomi contenenti spazi, sia pure con file con nomi contententi le più strane sequenze unicode (dagli emoji della birra a pure alle sequenze unicode non ancora definite nello standard).

Il quoting della shell, se usato correttamente, permette di gestire qualsiasi nome di file. Molti trovano difficolt

- (void)saveScreenshot
{
NSString * name = @"ciao";
BOOL includeStatusBar = NO;
//Get image with status bar cropped out
BOOL isRetina = [[UIScreen mainScreen] scale] != 1.0f;
CGFloat StatusBarHeight = isRetina ? 40 : 20;
CGImageRef CGImage = UIGetScreenImage();
BOOL isPortrait = UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]);
CGRect imageRect;
@andreafrancia
andreafrancia / 1955.py
Created November 11, 2012 20:08
Back to the Future in Python
# Copyright: (C) Andrea Francia 2012
# License CC BY-SA <http://creativecommons.org/licenses/by-sa/3.0/>
from __future__ import martin
try:
martin.dont_mess_the_continuum()
except martin.ParentsDontFallInLoveError, e:
(george, lorraine) = e.parents()
# Copyright: Andrea Francia 2012, lincesed under GPL-v2
from __future__ import martin
try:
martin.dont_mess_the_timeline()
except martin.ParentsDontFallInLoveError, e:
(george, lorraine) = e.parents()
while 'Enchantment Under The Sea':
import nose
class TestToBeRun:
def test_it_should_fail(self):
assert False
# possibly other test cases that should not be run
if __name__ == '__main__':
list_of_test_to_be_run=[TestToBeRun,]
@andreafrancia
andreafrancia / Prova.java
Created February 16, 2012 13:11
Equality for strings in Java
/* Run with:
javac Prova.java && java Prova
*/
class Prova {
public static void main(String[] args) {
StringBuilder o = new StringBuilder("o");
System.out.println("\"pippo\" == \"pippo\" ~~> " + ( "pippo" == "pippo") );
System.out.println("\"pippo\" == \"pipp\" + \"o\" ~~> " + ( "pippo" == "pipp" + "o") );
System.out.println("\"pippo\" == \"pipp\" + o ~~> " + ( "pippo" == "pipp" + o) );
@andreafrancia
andreafrancia / test_pywps_bug.py
Created September 1, 2011 13:49
Bug: PyWPS does not escape properly ExceptionText
import unittest
import sys
sys.path.append("./pywps-svn")
import pywps
import pywps.config
pywps.config.loadConfiguration('tests/pywps-no-logging.cfg')
class TestWps(unittest.TestCase):
def test_what_happen_on_process_errors(self):
wps = pywps.Pywps(pywps.METHOD_GET)
@andreafrancia
andreafrancia / test_wps.py
Created August 4, 2011 13:29
Bug encoding PyWPS
from nose.tools import assert_equals, assert_true
import sys
sys.path.append("./pywps-svn")
import pywps
def test_no_problems_passing_normal_chars():
wps = pywps.Pywps(pywps.METHOD_GET)
wps.parseRequest(
'service=WPS&version=1.0.0&'
'request=Execute&identifier=stub&'
@andreafrancia
andreafrancia / xpug
Created March 27, 2014 07:41
Pavia XPUG
Quando? giovedì 10 Aprile alle ore 7.00pm
Dove? TBD
Chi?
Paolo Raineri
Co-founder at MYagonism Netsporting
http://www.myagonism.com/