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

@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/
@andreafrancia
andreafrancia / gist:9551500
Last active August 29, 2015 13:57
Objective-C API for mock library inspired to Python Voidspace library
- (void)testMockery
{
Mockery * mockery = [[Mockery alloc]init];
id<AddressSink> sink = [mockery mockWithName:@"sink"];
[sink findAddressWithUUID:@"123"];
XCTAssertEqualObjects([mockery calls:^{
[sink findAddressWithUUID:@"123"];
}], [mockery trackedCalls:sink]);
#[cfg(not(test))]
fn main() {
use std::io::BufferedReader;
use std::io::stdin;
let mut stdin = BufferedReader::new(stdin());
match stdin.read_line() {
Ok(line) => println!("line:{}", line),
Err(io_error) => println!("problem reading line: {}", io_error)
}
- (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) );