The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

1
vote
1answer
17 views

How do I interpolate a text file of 3D coordinates (X,Y,Z) onto a regular grid?

I have a 3D surface in a text file which I need to plot on a regular X/Y grid. However, the values for X and Y are not regularly spaced and are not necessarily in ascending order. I need to regularly ...
19
votes
1answer
1k views

Why is /etc/shadow shortening the password that I've set with the command: useradd -p?

[root@P-dude dude]# useradd -p $6$Ic2PVlwi$2nf.IRWTMy0FHrPza6mh5wjomwbYtIIxnzxPZL7yg8SsvOdbjEpoI0G8uy7AqduYKQOn2R/rnnaalRmfPMy.a0 bwong20 [root@P-dude dude]# cat /etc/shadow | grep bwong20 ...
1
vote
1answer
34 views

Shell is not listed in /etc/shells, when it is

I must be missing something simple here, because I am trying to make a user's default shell "lshell" for limited access. I try to set the shell with the command chsh -s /usr/bin/lshell userbut it ...
5
votes
2answers
97 views

How can I use the output of a command without using the mouse?

Imagine you issued a find command and now you want to use one line of the resulting output as an argument. $ find .. fileA fileB $ vi <CURSOR> # now do what to achive: $ vi fileB ...
0
votes
2answers
65 views

Using regular expression to extract content of file [closed]

I have a link and I would like to return only content between www. and .com e.g www.blablabla.com would return only blablabla How could I do that? When I use grep '\.[a-zA-Z0-9\.-]*\.' it gives me ...
1
vote
1answer
34 views

zsh fails at path completition when command is vim

When I try to autocomplete files (with vim as argument 0): vim ~/.conf <TAB> It shows: _arguments:450: _vim_files: function definition file not found _arguments:450: _vim_files: function ...
4
votes
2answers
71 views

Millisecond time in a shell script

How can someone print the entire time ie, for example 12:07:59:393(HH:MM:SS:milliseconds) in milliseconds. I found a lot of posts saying how to print Milliseconds along witht HHMMSS but I want to ...
4
votes
2answers
277 views

Float operations with bc not precise?

When I'm performing float operations in shell using bc, the result is not the same if I use a regular calculator. Am I doing something wrong? For example, I need to find a volume of a sphere. User ...
1
vote
1answer
122 views

Evaluation of find ( -exec )

I'm searching for all files that contain one of a set of strings. If they do, I change their access rights. find . -type f -exec grep -q '#!/bin/bash\|#!/usr/bin/grep\|#!/usr/bin/awk' {} \; -exec ...
4
votes
3answers
487 views

Is there a Unix equivalent of the Windows environment variable PATHEXT

I am wondering if there is a Unix equivalent for the Windows environment variable PATHEXT. For those with no Windows background: Adding a file suffix to PATHEXT allows me to execute a script without ...
0
votes
1answer
21 views

Filtering time using last command on Solaris

I'm connected on server using Solaris and need to filter only people who were connected there until 28.4 00:00. How do I do that on Solaris? In bash I have -t option which does what I want.
0
votes
2answers
38 views

Why cant I overwrite a file with processed value?

This question prompted a thought I was not sure I understood well. I know that it is not possible or correct to use pipelines like cat myfile | grep -v mypattern > myfile due to how file handles ...
1
vote
1answer
30 views

Does gnome-terminal modify PATH when invoking shell

I guess gnome-terminal might have modified PATH environ variable when invoking shell. Specifically, $HOME/.local/bin:$HOME/bin will always be appended to PATH. I did the following experiment to ...
5
votes
2answers
31 views

What exactly happens if input and output file is the same?

Let's say that I execute following command: tr a-z A-Z < file > file There are two redirections: < file and > file. Both are processed before tr command and as far as I know, if there ...
2
votes
1answer
79 views

Play subtitles automatically with mpv

Subtitle files come in a variety of formats, from .srt to .sub to .ass and so on and so forth. Is there a way to tell mpv to search for subtitle files alongwith the media files and if it does to start ...
0
votes
1answer
40 views

Script too slow ? Any particular reason?

I have a script which does hexdump along with pipeline commands and finally I am redirecting it to a file. Now I am logging data from the serial port of my Raspberry Pi. I also call a python ...
0
votes
1answer
59 views

What is the meaning of xargs show limits output

You can use xargs to discover limits about the commandline you're using: $ xargs --show-limits Your environment variables take up 1901 bytes POSIX upper limit on argument length (this system): ...
2
votes
2answers
51 views

Delete directories that contain a certain file

I want to find all directories that contain a certain file and then delete those directories. With find . -name thatcertainfile -execdir pwd \; I get a list of all the directories I want to delete, ...
7
votes
1answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain? Thanks
-1
votes
4answers
48 views

How to filter the table names from .txt file [duplicate]

select * from emp; select * from dept; selection end; I want to obtain this output: select * from emp; select * from dept; I tried by using: awk '/select/{a=1} a; /;/{a=0}' ...
2
votes
4answers
100 views

How to delete a tilde (~) folder? [duplicate]

I need to delete a "~" folder in my home directory. I realize now that rm -R ~ is a bad choice. Can I safely use rm -R "~"?
1
vote
3answers
46 views

Elegant way of counting how many times patterns from a file occur in another file

Imagine that we have two for example files. The first file is filled with unique names of employees created by combining the first two characters of the first name and the last 2 characters of the ...
8
votes
4answers
558 views

Bash program not executed if redirection would fail

In bash, I notice that if a command using redirection would fail, any programs which run prior to that are not run. For example, this program opens the file "a" and writes 50 bytes to file "a". ...
2
votes
1answer
27 views

Unable to redirect stdout/stderr to log file [duplicate]

I have a script tmp.sh #!/bin/bash echo hello sleep 3 echo 3 I want to log the script running time (as well as script stdout) to a log file. user$ time ./tmp.sh >& log.tmp real ...
1
vote
2answers
45 views

cd to original location when recording session with “script” command

I have script log.txt in my bash profile; that creates a new sub process and records my entire session to log.txt. When I press cmd+t to open a new terminal usually this will open one in the same ...
0
votes
1answer
42 views

How to find the parent of a file by inode

I want to use ntfsundelete to maintain the directory structure of the recovered files. The output of ntfsundelete is like this: Inode Flags %age Date Size Filename 191321 FN.. ...
0
votes
1answer
63 views

grep with variable in a variable

I want to filter the svlog file by date and split the result by the space, so when i enter the date, it didn't work for me, please refer to the script that I wrote below, the problem was in this ...
0
votes
2answers
46 views

How to convert indentation style in a project directory

First of all I am not sure that this is the place to ask this question. I am a web developer working on a medium sized team. We follow the same coding style using Lint/Hint tools. It happens ...
0
votes
1answer
26 views

Why does Grave operator changes output format of the command? [duplicate]

Hello i want to ask why when i write ls -l there is new line after every row but when i assign it to a variable myVariable=`ls -l` and than echo that variable echo $myVariable i get ...
-1
votes
1answer
38 views

for loop to evaluate multiple directories and execute command

I was editing a shell script and I want to know how can use for to use all directories listed by a list or variables and then execute a command. Example: I have this directories: /dirname1/app1 ...
0
votes
2answers
28 views

Having trouble deleting specific directories within a specific parent directory

I’m using Amazon Linux, bash shell. I’m trying to write a statement that will delete all child directories named “target” within a specific master directory. I would like to write things such that ...
1
vote
1answer
47 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
0answers
27 views

What is the meaning of :- in unix? [duplicate]

Trying to understand the existing script where they have assigned ${3:-} to variable. Script : partition_parameter=${3:-} if [ -z $partition_parameter ]; then readonly drop_partition=false ...
0
votes
1answer
42 views

How do you put date and time in a file name?

I'm trying to execute a command and would like to put the date and time in the output file name. Here is a sample command I'd like to run. md5sum /etc/mtab > 2016_4_25_10_30_AM.log The date time ...
1
vote
1answer
47 views

Save cursor position and restore it in terminal

I am playing with some terminal capabilities to create async prompt output on bash. I want to get something like this: while outputting string in PROMPT_COMMAND, save terminal cursor position, print ...
-1
votes
1answer
25 views

Extracting several strings in a regexp

I have a FILE consisting of lines like the following: URL=http://someURL]somefilename I need to download the URL link if somefilename isn't already there. I wanted to use shell command like: for i ...
1
vote
4answers
46 views

Using cut to return the middle of a string

I have an xml string echoed to stdout along the lines of <xml:attribute>{41c33a-4893b-3627a-617a}</xml:attribute> I want to return the string {41c33a-4893b-3627a-617a} in this case. I ...
1
vote
1answer
38 views

Is there a standard abbreviation for 'find . -name foo' or do I need a function for this?

I recently used find . -name some-file-name a lot and decided that it's time to abbreviate this with a function (fb stands for find below): function fb() { find . -name "$1" } This seems to work ...
0
votes
2answers
23 views

Command Playlist like music.

So that idea has been in my head for a while, I often find myself launching a command and then wanting to launch another one after the one in progress finishes. The issue is that I have to monitor ...
0
votes
3answers
61 views

Comparing integers: arithmetic expression or conditional expression

In Bash, two integers can be compared using conditional expression arg1 OP arg2 OP is one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These arithmetic binary operators return true if ...
0
votes
2answers
49 views

What's the difference between using shell command (e.g. foo) directly and using $(foo)?

I get confused about using command directly and using $(foo). I'm using Mac, I try to list apps which is install by brew cask(a package manager), and echo each app. I have two short Shell scripts, ...
3
votes
1answer
151 views

Variables of integer type in Bash?

There are two ways to define and use variables of integer type in Bash declare -i a new variable use a variable in an arithmetic expression, without declaring it. My questions: What are the ...
2
votes
1answer
59 views

How can I check if a shell is login/interactive/batch in fish?

I want to be able to check if a fish shell is being run in login, interactive, or batch mode, and this question only discusses bash.
0
votes
1answer
44 views

Create HISTFILE in subshell

Here is my HISTFILE: $ echo $HISTFILE /home/Steven/.bash_history I can create it by using exit: $ [ -e $HISTFILE ]; echo $? 1 $ exit $ [ -e $HISTFILE ]; echo $? 0 However if I exit a subshell, ...
1
vote
2answers
19 views

Deleting lines by matching 3rd and 4th character only

I am running a script that fetches me the data as given below, 1400d2b8 1f4d1e2507 1200781e As you can see the 3rd and 4th character is 0 in line 1 and line 3. I am trying to write a single line ...
3
votes
3answers
36 views

How to pass array to bash shell script?

How do I pass an array as a variable from a first bash shell script to a second script. first.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') sh second.sh "$AR" # foo sh second.sh "${AR[@]}" # foo ...
3
votes
3answers
199 views

POSIX compliance of the cd program?

Is globbing and shell expansion same thing? I'm learning C by writing a custom shell and I'm also learning POSIX. Now I wonder if it is POSIX compliance that cd - takes you back and that ~ means home ...
-2
votes
1answer
40 views

Is a string an arithmetic expression?

In Bash, I use a string where an arithmetic expression is expected: $ (( hello )) $ echo $? 1 $ echo $(( hello )) 0 $ let aaa=hello $ echo $? 1 $ echo $aaa 0 There is no error reported. So is a ...
0
votes
0answers
13 views

TZ variable: strange behaviour using Etc/GMT+x? [duplicate]

Could anyone explain why the following commands return different results? TZ="Australia/Sydney" date TZ="Etc/GMT+10" date Sydney is 10 hours ahead of GMT, so the results should be equal, but I get ...
2
votes
1answer
27 views

Bash shell script program that prompts for and reads two integers from the user.

Okay, so I been trying to figure this problem for a while and I'm coming up with errors left and right. This is my first time trying to learn the basics. So any advice would be helpful! Problem: I'm ...