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
44 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 ...
13
votes
6answers
393 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
31 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
4
votes
1answer
54 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
335 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
35 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
91 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
66 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
26 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
93 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
71 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
84 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
92 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
37 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
66 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
19 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
317 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
77 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
108 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
56 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
41 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
70 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
52 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
40 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 ...
2
votes
2answers
68 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
19 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
116 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
51 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
30 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
489 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
333 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
80 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
97 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 : ...
1
vote
1answer
95 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 ...
1
vote
1answer
45 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
35 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 ...
0
votes
2answers
37 views

Change only the year on the output of the “date”-command

date for example displays Fri Apr 17 20:16:01 IST 2015 Now I want to change only the year so date should display Fri Apr 17 20:16:01 IST 2016 in this example. How to add 1 year to the output of date ...
2
votes
2answers
46 views

Local variable as a part of global one

I have a question about something similar to this question, but I need to call global variable depending on local one. Say I want to pass either test, staging, or production as a variable to a ...
3
votes
1answer
38 views

Shell glob - substitute file path arg with file's contents

In curl command, there is --data option, which substitutes the file contents when the option value is prefixed by @ symbol like, curl -X POST --data @abc.json hostaddr.com abc.json file contents ...
16
votes
3answers
599 views

When I cd through a symlink, why does pwd show the symlink instead of the real path?

I created a soft link (ln -s 1 2) to a directory which is inside the test directory and opened the soft link (cd 2) and displayed the current path using pwd. The displayed path was ~/test/2 and not ...
2
votes
1answer
23 views

Quoting: loop over ssh-accounts, call psql on remote server

This works in the human brain, but the shell misses quoting: for h in a b; do ssh $h psql -tAc "select * from mytab where mycol='x'"; done How to quote this one liner without loosing readability?
0
votes
1answer
51 views

How can I get a shell script to change directory for me? [duplicate]

here is a small test I ran, to try and move me back to root: #!/bin/bash pwd cd / pwd It returns the current working directory, and then the correct new one, but when the script finished executing, ...
3
votes
2answers
195 views

The «sh» being launched with execl() becomes a zombie

I am spent whole half a day, but still couldn't figure, why is the dash being launched with execl call just becomes a zombie. Below is a minimal test case — I'm just fork a child, make a duplicate of ...
1
vote
1answer
46 views

using `for file in` to select multiple extension names then get the basename of “file” then concatenate an extension name

I am trying to practice my unix skills, I just learned how to use for file in *.jpg; what it does is select all files with .jpg in the working directory, but I do not want to stop there and I do not ...
0
votes
1answer
52 views

how to write a shell script to run multiple programs

I want to run two programs ssh -f mike@c15-0330-02 'cd /home && nohup Rscript L_1.R> L_1_sh.txt ' AND ssh -f mike@c15-0330-03 'cd /home && nohup Rscript L_2.R> L_2_sh.txt ' I ...
0
votes
0answers
43 views

Need to have password coded in script [duplicate]

I have to login many Servers day in day out by supplying passwords manually. Now I want to know or have a script where from I can login to any server without password (I mean to say if the ...
0
votes
1answer
55 views

shell script unable to set environment variable with the grepped value

In the shell script, I want to grep a value from the log file and set as the value of one environment. In the log file, there is one line like this: SOME_PATH=/some/specific/path In my shell ...
1
vote
1answer
53 views

Cut some fields from a text file to another

I have the following command: grep -owf champs.txt t.txt and I want to cut the result of this command from the file t.txt to another file. I know that it can be achieved by a nested command but I ...
1
vote
2answers
90 views

How are long command lines ( > $COLUMNS ) automatically wrapped to a new line?

There are several points where I/O is passed through, some of which (to my knowledge) are the shell, pty, tty, termios, terminal emulator application. In most terminal emulators, long command lines ...