The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
2answers
99 views

Execution of a command in a variable with eval

I am trying to use grep to color some log files . I wrote a script and a part of it looks like this : #!/bin/bash com="GREP_COLOR=\"1;36\" egrep --color=always '[^a-zA-Z0-9]' $log |less -R" ...
0
votes
5answers
63 views

How can I modify variables

I have the following variable: col=1,3,4, Is there anyway to select the numbers within the variable: (i.e. 1 3 4 and work with them? Such as choosing the "1", "3", or "4" column from a .txt file? ...
1
vote
1answer
59 views

prevent bash completion from altering underscore variable $_

When using tab completion in bash, the $_ variable is altered: $ mkdir test $ cd <TAB><TAB> $_ bash: cd: -d: invalid option cd: usage: cd [-L|[-P [-e]]] [dir] (The ...
1
vote
4answers
98 views

Reusing a variable

I was breaking my head for a day still not successful. I have this script: #!/bin/ksh fname=$1 for batchname in $(grep -i "Processing batch" $fname | cut -d "'" -f2) do Batch_state=`grep -c -i ...
0
votes
2answers
59 views

Why must you be careful when using Bash's built in command history function to re-run previous commands that contain variables?

I know !! re-runs commands but what exactly would occur if I re-ran a command that had a variable in the command?
0
votes
1answer
50 views

LD_LIBRARY_PATH not found - CentOS

I am trying to run the following two commands... LD_LIBRARY_PATH =/opt/oracle/instantclient_12_1 export LD_LIBRARY_PATH But when I run the first command I get an error -bash: ...
1
vote
2answers
110 views

how can I add (subtract, etc.) two numbers with bash?

I can read the numbers and operation in with: echo "First number please" read num1 echo "Second mumber please" read num2 echo "Operation?" read op but then all my attempts to add the numbers fail: ...
1
vote
2answers
40 views

awk,how to change the value of the file using parameter sets?

I am trying to reset my data using awk. I have a data of 54 columns where I want to change six of the column values using the following script. #!/bin/bash -x # optimal parameters set ...
2
votes
2answers
68 views

Creating temp file vs process substituion vs variable expansion?

If I am doing something like creating temporary file some process generating output > temp_file cat temp_file process substitution: cat <(some process generating output) another way : ...
2
votes
4answers
82 views

Scope of variables when calling function from find

In a bash script I define a function that is called from find. The problem is that the scope of variables does not extend to the function. How do I access variables from the function? Here is an ...
2
votes
1answer
31 views

How to take advantage of gnuplot internal functions by column reference at shell

I want to do something like: echo "p 'myfile.txt' u 1:(exp($2))" | gnuplot -p but need the shell to pass the $2 as a literal into gnuplot.
2
votes
4answers
130 views

Can awk use field identifiers also for shell strings (variables)?

Well, this apparently is not possible the way I'm trying it. This alternate approach to obtain bar as a resulting string works, though: #!/bin/bash path1=/usr/tmp/foo/bar/baz awk -F/ '{print $5}' ...
2
votes
4answers
131 views

Setting a variable whose value depends on another variable

i have a text file variables.txt where i store my variables host=/srv/www/vhosts/hosting index=$host/index.php as you see the second variables depends on the first one. i also have a ...
2
votes
1answer
87 views

prevent trap from altering underscore variable $_

I have the following code in my bashrc to get the execution time of the last command from http://stackoverflow.com/a/1862762 function timer_start { timer=${timer:-$SECONDS} } function timer_stop { ...
40
votes
2answers
2k views

What NOT to put on an SSD?

I bought an SSD and I am going to set up my desktop system with a completely fresh Linux installation. SSDs are known to be fast, but they have a disadvantage: The number of writes (per block?) is ...
1
vote
2answers
39 views

Associating variable with specific for loop file

I want to use for for a set of files. for file in fileA fileB fileC; do COMMAND $file $variable done For every $file I want to use specific $variable. (for example: fileA variableA; fileB ...
1
vote
2answers
99 views

for loop to get more than one arguments

In python and some other programming languages, it is easy to get a vector instead of one variable everywhere and in loops. like python: for variable in ...
0
votes
1answer
66 views

How can I use a variable from a script?

A bash script is running as I defined it in Startup Applications. It is possible to display on terminal a variable used in that script? If yes, how?
2
votes
1answer
97 views

What does “${x%% *}” mean in sh? [duplicate]

I just saw "$${x%% *}" in a makefile, which means "${x%% *}" in sh. Why it is written in this way ? how can a makefile detect whether a command is available in the local machine? determine_sum = \ ...
0
votes
2answers
669 views

bash - reading user variable into bash script grep

I've tried every possible combination to get this bash script working. It's part of a larger script, and it basically prompts for a username (to check if it exists) and returns the appropriate ...
2
votes
2answers
66 views

List all my variables [duplicate]

I'm just learning the basics, including how to declare and mess around with variables. Is there a simple way to display a list of all the variables I've named? (Everything I've found by searching only ...
0
votes
1answer
151 views

How can I preserve new lines coming from a command's output during variable assignment?

Consider: $ getfacl somefile.dat # The output is formatted and contains several new lines.. # file: somefile.dat # owner: user1 # group: group1 user::rw- group::r-- #effective:r-- ...
1
vote
2answers
108 views

How to print shell variables and values to be able to copy/paste them?

In Bash 4.2.25, the set and env output is not escaped, so shell escapes and any non-printable characters won't be copy-pasteable. Take for example this shell session: $ export foo=$'a\nbar=\baz' $ ...
1
vote
1answer
137 views

What does mean ` AWK=@AWK@` in shell scripting

I found AWK=@AWK@ while reading sh script, it's something like AWK=$(which awk), but it's not working. So can anyone explain this ? Script : #!/bin/sh - # makelist.sh: Automatically generate header ...
1
vote
2answers
238 views

How do I set bash aliases and variables from within vim?

In cmdline mode, the following examples do not work for me. !alias lol='echo lol' !lol='echo lol'
2
votes
1answer
212 views

shell variable in awk is not being passed to all the lines but just for the very first line of input?

inputfile:is2.txt 10.39.5.41,A1,B1 10.39.5.41,A2,B2 10.39.5.41,A3,B3 10.39.5.41,A4,B4 10.39.5.41,A5,B5 10.39.5.41,A6,B6 script : #!/bin/bash second_column="OOOOOOO" # OOOOOOO will be added to ...
3
votes
2answers
122 views

Setting a shell variable in a null coalescing fashion

I'm really fond of "null coalescing", where you can set a variable to the first "non-null" value in a list of things. Many languages support this, for example: C#: String myStr = string1 ?? string2 ...