2
votes
2answers
49 views

In bash, how I define a “command scope” variable?

I'm reading this book on the bash architecture and one of the bash maintainers says: There are different variable scopes for shell function calls and temporary scopes for variables set by ...
1
vote
4answers
30 views

How do I test whether a variable has multiple non-blank lines in bash?

Say I have two variables in bash: MULTILINE="I have more than one line" SINGLE_LINE="I only have one line " I want to detect when a variable actually contains more than one line of text, ...
1
vote
2answers
49 views

Bash determine whether parameter variables ($1, $2, $3, etc.) have been set

Many of the posts I just read have many answers that cover this, but I don't understand what I'm doing really; it's been hit & miss. The .sh script I'm working with: #!/bin/bash # init ...
0
votes
2answers
20 views

confused about variables in bash

I know that variables in bash have no type, but am confused about the value they are assigned. The following simple script works fine in bash #!/bin/bash tail -n +2 /cygdrive/c/workdir\ \(newco\,\ ...
0
votes
1answer
73 views

Append an index number to a variable name in bash?

I am trying to loop through numbered variables but am having a hard time appending the loop index number to the base variable name. Code follows, using a 2-iteration example: #ENTER TOTAL NUMBER OF ...
0
votes
1answer
135 views

How do I use variables in bash to output to a file and to a mail body with sendmail

I've been working on this little script and it's nearly at a point that I can start using it. The idea is to automate WordPress installs via Plesk. I've got Plesk setup with a cronjob to download ...
1
vote
1answer
116 views

bash: run output of another command, with variable substitution

In bash, I often run awk programs with many preset variables. Most of the times I use the same variable names in both bash and awk, so I call awk like the following: awk -v var1="$var1" -v ...
1
vote
1answer
38 views

space at the end of variable is killed on output

I'm on Ubuntu 12.04 with bash 4.2.25(1)-release. If I use #!/bin/bash echo -n 'test ' > text; echo 'test2' >> text; everything works fine and the output of text is test test2. But if I use ...
2
votes
3answers
286 views

Bash script to print files that have a certain line length

I'm new to this… I need a script that receives a directory as a parameter and prints the names of files that have between 15 and 50 lines, but I don't know how use the wc output in an if-sentence: ...
3
votes
0answers
194 views

Bash auto-completion af variables adds additional white space at the end

when I perform an auto-completion of a bash variable an additional white space is added at the end. $FO[TAB] -> $FOO" " I added the quotes in order to denote the white space. The problem is ...
1
vote
2answers
91 views

Newlines while saving variable to file - bash

I have mulitiple ip adresses in a variable. ActiveIPs= 192.168.0.1 192.168.0.2 192.168.0.3 I want to save them to a file like this 192.168.0.1 192.168.0.2 192.168.0.3 how do i do this?
2
votes
2answers
196 views

tilde expansion fails when running “cd -” in bash

Recently I find I can't use cd - to go back to last directory sometimes. It gives the error of -bash: cd: ~/whatever_dir: No such file or directory. A closer look shows that the error only happens if ...
3
votes
4answers
193 views

*NIX - does exporting a variable only last while machine is on?

I know that I can set a variable, 'export' the variables and put an alias statement in my .bash_rc file. So: When I just set a variable it just lasts for that session and is not visible to other ...
3
votes
5answers
2k views

xargs command works on ubuntu, but not mac

I have the following line of code that I use to update my personal date variable in my projects to today's current date. This line works in Ubuntu's terminal, but the Mac terminal seems to be far ...
0
votes
1answer
97 views

BASH: Bracketing Parameters

Simply, whats the fundamental difference between $param and ${param} ?