All Questions

3195
votes
45answers
2267686 views

Calling an external command in Python

How can I call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
43
votes
8answers
63487 views

Arrays, linked lists and other data structures in cmd.exe (batch) script

I was playing with cmd.exe, but in its help I didn't find any info, how to define arrays. I have found, how to define simple variables: set a = 10 echo %a% But, I want to create arrays, linked lis...
277
votes
3answers
73387 views

Difference between single and double quotes in Bash

In Bash, what are the differences between single quotes ('') and double quotes ("")?
63
votes
4answers
16596 views

When to wrap quotes around a shell variable?

Could someone tell me whether or not I should wrap quotes around variables in a shell script? For example, is the following correct: xdg-open $URL [ $? -eq 2 ] or xdg-open "$URL" [ "$?" -eq "2" ...
920
votes
13answers
1038314 views

How to set a variable to the output from a command in Bash?

I am working on a simple scripting project for work that involves the use of Bash. I have a pretty simple script that is something like the following: #!/bin/bash VAR1="$1" VAR2="$2" MOREF='sudo r...
139
votes
6answers
285851 views

How do I use shell variables in an awk script?

I found some ways to pass external shell variables to an awk script, but I'm confused about ' and ". First, I tried with a shell script: $ v=123test $ echo $v 123test $ echo "$v" 123test Then trie...
357
votes
4answers
257687 views

Command not found error in Bash variable assignment

I have this script called test.sh: #!/bin/bash STR = "Hello World" echo $STR when I run sh test.sh I get this: test.sh: line 2: STR: command not found What am I doing wrong? I look at extremely...
1363
votes
31answers
1441321 views

How do I split a string on a delimiter in Bash?

I have this string stored in a variable: IN="bla@some.com;john@home.com" Now I would like to split the strings by ; delimiter so that I have: ADDR1="bla@some.com" ADDR2="john@home.com" I don't n...
29
votes
4answers
27195 views

I just assigned a variable, but echo $variable shows something else

Here are a series of cases where echo $var can show a different value than what was just assigned. This happens regardless of whether the assigned value was "double quoted", 'single quoted' or unquote...
743
votes
20answers
470461 views

Why do people write #!/usr/bin/env python on the first line of a Python script?

It seems to me like the files run the same without that line.

Previous Next