All Questions

Filter by
Sorted by
Tagged with
1
vote
1answer
48 views

How do I return octal from Bash's arithmetic expansion?

As clearly spelled out in the Bash documentation on shell arithmetic, if you prefix a number with a 0 within an arithmetic expansion expression (e.g., $(( expr ))), it's treated as octal. Similarly, ...
8
votes
4answers
788 views

Bash Read: Reading comma separated list, last element is missed

The output of the command below is weird to me. Why does it not give me back element 5? $ echo '0,1,2,3,4,5' | while read -d, i; do echo $i; done 0 1 2 3 4 I would expect '5' to be returned as well. ...
0
votes
2answers
61 views

How can i echo the value of [ 4 -gt 3 ] ,that is a test expression in bash?

How can I echo the value of [ 5 -gt 4 ] ,that is a test expression in bash? [ 5 -gt 4 ] | echo and echo `[ 5 -gt 4 ]` both end up printing a blank line @Thomas Dickey 's answer works but could ...
1
vote
3answers
112 views

Shell: only double quote on test -n/-z? [duplicate]

In case of test -e for example: VAR="<this is a file path: /path/to/file/or/dir" test -e $VAR && do_something || do_anotherthing Question: Should I use "$VAR" here?, here I don't like ...
0
votes
1answer
41 views

How can I extract a function from bash/zsh with all its shell-related dependencies?

I write a lot of little useful functions, and sometimes I like to share them with friends or the world. The problem is that I use a lot of my helper functions and aliases in my functions, and I don't ...
1
vote
1answer
941 views

Password Encryption [duplicate]

I have a Migrate.ksh file, in that some passwords are available, I would like to encrypt this file in the Unix. The Passwords file being used in another script. Can you please let me know the process ...
1
vote
0answers
27 views

What is the behavior of `command`? [duplicate]

According to this comment which is in defense of the author's answer, @einpoklum Yes, it is necessary. In fact, even this solution may break in one edge case. Thanks for bringing this to my ...
-2
votes
1answer
172 views

Shell Script for formatted output [closed]

06/26/2017 23:40:40 CAUAJM_I_10082 [aspsun14 connected for IOALPPRXXBD_ALPGLGENFAALL 55443.15215291.1] 06/26/2017 23:40:40 CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: STARTING ...
45
votes
8answers
4k views

Why are POSIX mandatory utilities not built into the shell?

The purpose of this question is to answer a curiosity, not to solve a particular computing problem. The question is: Why are POSIX mandatory utilities not commonly built into shell implementations? ...
1
vote
0answers
182 views

How to write decorator commands [duplicate]

I don't know the exact word, that's why I'll use "decorator", like in POO, but I'm talking about the kind of functions you can use before other functions to add any operations to it, like the command ...
12
votes
4answers
1k views

Use case / practical example for Bash' builtin exec

Consider this from the documentation of Bash' builtin exec: exec replaces the shell without creating a new process Please provide a use case / practical example. I don’t understand how this makes ...
2
votes
2answers
205 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
4
votes
2answers
1k views

The type command can't distinguish between an executable command and a shell script

So I was reading the book The Linux Command Line, and it says that commands are of four types: (1) executable programs (2) shell builtins (3) shell functions (shell scripts) (4) ...
10
votes
2answers
16k views

Count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable)

Brief statement of the question: Is there built-in bash method to count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable), without resorting to ...
11
votes
1answer
1k views

Is “wait &” (“wait ampersand”) a useful (bash) shell / shell script idiom or technique?

I've "inherited" some shell scripts for Linux machines running the GNU "bash" shell. In one particular case, the machine runs GNU bash version 2.0.5b One of those scripts has a wait & ("wait ...
0
votes
1answer
973 views

reading file using for, while - behavior

Consider the below scenario 2 vms - 192.168.229.131, 192.168.229.132 Both the vms has it's ip as 192.168.229.151 & 192.168.229.152 in it's /etc/hosts file Say there are around 50 vms like I ...
13
votes
4answers
5k views

How to invoke a shell built-in explicitly?

I want to customize the functionality of cd command as per my needs. I defined the following function - function cd () { cd "$@" && pushd "$@"; } The intent of this function is to ...
10
votes
3answers
3k views

Possible to use brace (permutation) and array expansion simultaneously?

Bash's {} brace expansion syntax allows for creating easy permutations # echo {b,c,d}{a,e,i,o,u} ba be bi bo bu ca ce ci co cu da de di do du However it's not clear to me if/how it's possible to use ...
44
votes
7answers
10k views

What purpose does the colon builtin serve?

I've hacked on a lot of shell scripts, and sometimes the simplest things baffle me. Today I ran across a script that made extensive use of the : (colon) bash builtin. The documenation seems simple ...