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)

3
votes
2answers
246 views

Why I should avoid loops in shells? [duplicate]

The following link recommends against using loops in shells. bash variables in for loop range Why is this? Here is an example loop I just happened to be looking at when I came across that answer: ...
1
vote
1answer
31 views

Python now thinks arguments are files: Broken emerge, pip, livestreamer and most tools using Python

For these commands (in both bash and fish): sudo emerge eix emerge eix I get this error: usage: emerge [-h] [--version] [input [input ...]] emerge: error: argument input: can't open 'eix': [Errno ...
0
votes
1answer
25 views

Multiple input files and output files in awk

I have a folder full of text files named 000.txt to 181.txt. How can I process all of them with the same awk script (program.awk) and send them to their respective output files (output000.txt - ...
1
vote
1answer
20 views

Unzip specific files from multiple zip files

I'm new to Unix and am trying to extract specific pattern filename from the multiple zip files. I'm using find to find the zip files, and then trying to extract files having the filename CTL in the ...
6
votes
2answers
107 views

Exclude one directory in `ls` matching pattern

I'm trying to ls dirs that have .png files inside (no need for recursiveness, though it would be extra useful), exept one. Exlude one directory i.e. ls */*.png works fine. ls (^one)*/*.png ...
0
votes
1answer
42 views

command “find … -exec mv …” created a file with strange content

I wanted to move binary files from folder /myhome/sourcedir to /myhome/targetdir. I used a command find /myhome/sourcedir -type f -cmin +3 -exec mv '{}' /myhome/targetdir ';' Folder /myhome/sourcedir ...
2
votes
2answers
26 views

Git alias multi-commands with ; and &&

I want to have an alias that execute a command and then whether it fails or no it execute other commands that depends on the success of each other. So I have something like that in .gitconfig ...
0
votes
0answers
41 views

Shell intervals using awk

I have a file a 10:10 10:30 b 12:15 13:15 c 16:54 17:54 and I need to enter interval for example 10:15 so my output should be a 10:10 10:30 How I need to do that using awk?
-1
votes
0answers
30 views

Shell script for electrum - how to add the seed? [on hold]

I use a diskless web server with a live cd and looking for a possibility to restore my electrum wallets automatically by a seed. I would like to implement a script that performs this task for me. so ...
0
votes
1answer
24 views

Feeding audio from microphone live into python

Well, so I was reading about this raspberry pi tutorial that makes you play audio files from raspberry pi and stream them into a FM signal and something got me curious. You can stream .wav files, ...
1
vote
1answer
28 views

Get first/second file column

I have two for loops here for i in $(cat "firstFile.txt") do for j in $(cat "secondFile.txt") do if [ "$i" = "$j" ]; then echo $i[$2] # use first file second column ...
11
votes
6answers
318 views

/bin/dash: check whether $1 is a number

What would be the best way to check whether $1 is an integer in /bin/dash ? In bash, I could do: [[ $1 =~ ^([0-9]+)$ ]] But that does not seem to be POSIX compliant and dash does not support that
-1
votes
1answer
20 views

How do I set an environment variable in the shell to be result of python script? [duplicate]

If I run export TEST=script.py echo $TEST It outputs script.py script.py code: return 5 can TEST be set to 5? Obviously script will do something in future not just return a number
2
votes
1answer
35 views

Using nice on bash (or other) subshell?

Say I'm working on a sluggish system and notice (say via top) that CPU usage is up around 100%, but I don't want to kill the process. If I want to do other work on the machine and just make that ...
5
votes
3answers
316 views

Compare the heads of two files in bash

I can do diff filea fileb to see the difference between files. I can also do head -1 filea to see the first line of filea or fileb. How can I combine these commands to show the difference between the ...
0
votes
1answer
24 views

umask getting sets to 022 even though all necessary files are modified

umask is creating lots of problem to me . I tried following . I have commented umask set entry in /etc/profile and /etc/bashrc . There is not even single file in my home direcotry where i set umask ...
0
votes
4answers
65 views

Foreach loop for ls output

I am trying to process some files in directory using foreach loop for ls output: IFS=$'\n' for i in $(ls -1Atu); do echo "$i" done At first time i thought it works, but when i created file ...
3
votes
2answers
60 views

List direct symbolic links (links that don't point to another symlink)

I need to make a list of all direct symbolic links in a directory, i.e. symbolic links that point to another file which is not a symbolic link. I tried to do it this way: for i in $(ls -1A); do ...
0
votes
1answer
23 views

How can I add default command line parameters to an executable in a way that will also work on GUI apps? [duplicate]

I want to pass a command line program by default when I run it. myprog --foo=bar The solution I could think of was to add a custom "myprog" wrapper to my "bin" folder #! /bin/sh /usr/bin/myprog ...
2
votes
2answers
53 views

ls pattern matching

I know that [] is working in ls pattern matching: $ ls foo.c foo.h $ ls foo.[ch] foo.c foo.h but I cannot find where this is documented. I would like to know the syntax that would match these: ...
3
votes
2answers
61 views

Linux redirection: << operator [duplicate]

Can anyone explain when and how to use << operator for input redirection? I've googled enough but couldn't find.
2
votes
1answer
18 views

Default umask for cron jobs

How to set default umask for cron jobs, please? (On RHEL 6.) Jobs are started under non-interactive (obviously) no-login (?) shell. Not only I prefer dash over bash. But consider also bash called as ...
1
vote
2answers
84 views

cat < file.txt Who is the responsible of reading the file?

cat < file.txt Who is the responsible of reading the file ? Is the shell reads the open and read the file then write its content to the standard input of the command ?
0
votes
2answers
25 views

Exclude the output from ssh and only log the error if found

typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} " $(cat); IFERROR=$(checkscript); echo "$IFERROR"" > ${SSHTEMPFILE} 2>&1 This line...I can't exclude the ...
0
votes
2answers
31 views

How to edit what is typed in command line?

Typing a command like: cat somefile Press enter and run the command. Then searching for it using ESC + k, allows me to bring it back. I want to go back and edit the command while still typing in ...
0
votes
2answers
58 views

Having trouble with basic if then statement

learning the basics of scripting and I have this line of code: #!/bin/sh if [ $# -ne 1] then echo "Please provide one directory to search" echo "Example usage: something.sh directory_name" ...
1
vote
1answer
18 views

Dotfile not working in current shell, need new one

To be clear, this isn't a screen issue, I'm sure it's a general shell issue. On a new Ubuntu 12.04 server, I'm currently logged into a terminal in which I want to run the screen command with my ...
3
votes
1answer
180 views

Linux: set command for local variables

I am trying to understand local/environment variables and export/set commands. $ set FILEM="razrax" $ echo $FILEM $ FILEN="test" $ echo $FILEN test Please explain why echo $FILEM returns empty ...
-3
votes
3answers
54 views

Delete line from files

I have 8 files in a folder. If any of these files has 2 lines I need to remove the second line from that file. If a file has more than 2 lines then then I do not need to do anything to it. Can anyone ...
1
vote
1answer
96 views

How to tell the sizes of files and folders, sorted, and in MB, GB, instead of a long integer? [duplicate]

On a Mac, using Bash, I tend to do du -sh * to tell the sizes of files and folders in the current directory, in MB and GB. But if I want to sort them by the sizes, I might do du -sh * | sort -g ...
2
votes
1answer
55 views

Download a file to a server?

After ssh to a server, I want to download two files in https://iain.cx/src/ktmux/#download to the server. So for the first file ktmux_helper, I right click to find its link on my local computer, and ...
2
votes
1answer
33 views

Prevent glob expansion in foo=“*”; echo $foo [duplicate]

In Bash, when I do: foo="*" echo $foo It expands * to the contents of the current folder. How do I make sure it just prints a literal *? The same, by the way, happens with a regular echo "$foo", ...
1
vote
2answers
37 views

CentOS 7 shell script interpretor

I am starting to write a shell script to be run in CentOS 7. Which interpreter should it call, and what should the shebang line look like? I tried this: #!/bin/sh But when I type cd /bin ...
2
votes
1answer
45 views

How to I prevent exec from keeping the script running?

I'm using exec like this: #!/bin/bash exec > >(tee /tmp/mylog.log) 2>&1 bash -c 'sleep 12312' & I want the output of the commands to be in a log file, and then I want to start a ...
1
vote
1answer
35 views

In-place substitution for paste command [duplicate]

When I run the following code echo '1' > file.txt echo '2' | paste file.txt - > file.txt I would expect the content of file.txt be 1 2, because the paste command as it name suggests should ...
-1
votes
1answer
28 views

Quoting a URL string containing & in sh script [closed]

I want to put quotes "" marks around a string which has the & symbol in it. If I echo the string, the shell treats the string as two commands, ie. separated by the &. Looking for something ...
2
votes
2answers
53 views

Use alternatives or adding to PATH?

I'm a bit confused about the proper way to make a script globally available from the terminal, like a command. There are two ways, using the alternatives utility, basically making a symlink to ...
1
vote
0answers
13 views

Setting custom baud rate on console

Just for aesthetics I would like to have my text on my console be displayed at a lower speed. I've tried using things like screen with custom baud rates of /dev/tty1 but it wouldn't work, input from ...
4
votes
2answers
85 views

how to sort by the day of the week?

I have two files. file1: Dave 734.838.9800 Bob 313.123.4567 Carol 248.344.5576 Mary 313.449.1390 Ted 248.496.2204 Alice 616.556.4458 file2: Bob Tuesday Carol Monday Ted Sunday ...
0
votes
3answers
41 views

Bash: Access parameter passed to last command [duplicate]

This is a situation I often find myself in: mkdir /Some/really/long/path/to/a/directory/ cd /Some/really/long/path/to/a/directory/ I know that ideally you would cd /Some/...etc.../a/ and then mkdir ...
-3
votes
2answers
29 views

What is the exact difference between “/” and “%” in the expr command?

I want to know the difference between "/" and "%"! When I type and run the following command I get 0: expr 4 % 4 But when I run same command and replace "%" with "/" I get 1 expr 4 / 4 Thanks
4
votes
3answers
477 views

Echo command with AND operator doesn't exit

echo hai && echo bye prints hai bye while echo hai && echo $? prints hai 0 When the first echo command's return value is 0, how does the echo statement after AND operator ...
7
votes
2answers
324 views

How to store a large folder in a single file without compression

Sorry if this is a stupid question, but I want to take a 78gb folder and store it in a single file (for upload into a cloud service), as if I am compressing it in an archive, but I don't want any ...
2
votes
2answers
51 views

Create variables and assign values via loop (bash)

Is there a way to create bash variables and assign them values via a loop? Something along the lines of: #!/bin/bash c=0 for file in $( ls ); do var"$c"="$file"; let c=$c+1; done EDIT: ...
1
vote
2answers
78 views

How can I select 3 character files in Bash?

I know that a question mark is considered a special character and it has special meaning. Question mark represents a single character that can be any type. In my practice lesson we have an example : ...
0
votes
0answers
25 views

Show last x lines of a screen session?

/etc/init.d/mc {..} status) if screen -ls | grep -q "mc"; then echo -e "[\033[32mMC\033[0m] Online" {.. needed code ..} else echo -e ...
1
vote
1answer
74 views

Bash script won't work on current directory

I'm using Kali linux which is based on Debian and wrote an script to copy some files from where the script is based to a specified directory. But when I execute my script (called CopyFiles.sh), cp ...
0
votes
0answers
15 views

Create user, directory, vhost, and mysql user faster? [closed]

I host a lot of my client websites on my dedicated Ubuntu Server (14.12). I really need a faster way to create a directory for a new client then manually creating the user, the mysql user, assign the ...
1
vote
1answer
40 views

Can't use find -print in AWK

I'm trying to put together a command to find SUID System Executables, which are not the default ones in RHEL. To do this, I'm pulling a list of the local File System (df --local -P), piping it over ...
3
votes
1answer
33 views

How to inspect the raw contents of a partition?

I'm trying to see the contents in raw bytes of a dummy partition /dev/sda3, which I've made to be 100MiB through gparted. I want to test writing and reading on that partition. Is there a tool that ...