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
48 views

is it possbile to add comma in this SQL?

I have a statement like this UPDATE `test`.`scores` SET id=1 name='kobe' score=99 WHERE id=1 name='kobe' score=100 UPDATE `test`.`scores` SET id=2 name='tmac' score=70 ...
4
votes
1answer
469 views

which bash is executing?

I think I have configured bash as shell, but why is this happening? My shell is bash: # ls -al `which sh` lrwxrwxrwx 1 root root 4 Jul 12 03:25 /bin/sh -> bash Error executing a script with ...
1
vote
2answers
93 views

what's the simplest way to increment the numbers in this string 01:02:99 in unix?

What is the simplest way to increment the numbers in this string 01:02:99? Expected output: 01:03:00 I'm hoping for a sed response, but I don't think it would be simple.
2
votes
2answers
29 views

finding a folder names based on list contained in .txt file

I have a .txt file containing 150 different ID number on each line like so: 12345 15876 19643 12586 Located in the same directory as the .txt file, I have 300 folders and I want to copy only the ...
2
votes
2answers
48 views

Bash function comments before or inside the function [closed]

Does the Bash language have a standard that dictates whether comments about the function should precede the function or be placed inside of it. I have seen scripts written both ways. # Comment ...
1
vote
2answers
24 views

Mail one liner to check if null before sending [duplicate]

I'm trying to modify a script which emails a user group the contents of a directory. The modification I'm looking for is to check the script below to see if it has valid output before sending. The ...
0
votes
1answer
33 views

Why does my terminal say I'm running -bash (with a leading dash) and not bash?

I have recently started learning UNIX for a week or so and I've played around with the bash_profile and bashrc files to add in some basic preferences. But today, I couldn't execute several terminal ...
3
votes
2answers
101 views

How can I start several processes with a single command?

I use pianobar player. But before launching it I need to run tor and polipo. Both are continuous (are running until interrupted). Basically what I'm looking for is a single command which would spawn ...
1
vote
2answers
92 views

Escalate permissions through a background shell script

I would like to write to a Device File (of a printer) located at /dev/usb/lp0. The file is owned by lp user and group. This file is created whenever I connect my printer device to the system. I ...
4
votes
3answers
102 views

How to print same lines multiple times with variables changed using Sed/Awk/ anything?

a. Have set of lines as given below. cr_v8_sel0 : cross cp_v8_en, cp_sel0 { ignore_bins ig_v8_sel0 = binsof(cp_v8_en) && binsof(cp_sel0) intersect {[0:3],[5:$]}; } b. I wanted to print ...
3
votes
0answers
114 views

How can I run 'ls' with options from a C program? [migrated]

I want to execute the command ls -a using execv() on a Linux machine as follows: char *const ptr={"/bin/sh","-c","ls","-a" ,NULL}; execv("/bin/sh",ptr); However, this command does not list hidden ...
0
votes
3answers
55 views

Delete last line of gz file

I need to delete the last line of gz file without uncompressing. The file has 500 lines. How can I do that? I have tried: gzip -dc "$files" | tail -500 | gzip -c > "$files".tmp But It doesn´...
3
votes
2answers
55 views

How to Run a command on all subfolders

If you have a series of sub folders (like from a to z) and want to run a command on each one of them (like dsmmigrate * & ) how do you do that? The manual approach would be, cd a dsmmigrate * &...
0
votes
0answers
55 views

What are the minimum required environment variables? [migrated]

I am writing a shell. With the execvpe system call, I can run a program and control its environment. What are the minimum values I need to pass through here? Alternatively, I understand that child ...
1
vote
0answers
19 views

convert windows path to unix path inside wine application command line

I'm running a windows application in wine, which executes configurable commands to run external applications (e.g. an diff editor to show differences between two source files). So these commands are ...
2
votes
2answers
67 views

bash:Syntax near unexpected error '(' [closed]

I am following a tutorial in computational microbiology: William Lindstrom, Garrett M. Morris, Christoph Weber, and Ruth Huey (2008-01-29). Using AutoDock 4 for Virtual Screening. Scripps Research ...
4
votes
2answers
106 views

Replacing only specific variables with envsubst

I'm trying to perform environment variable replacement through envsubst, but I want to only replace specific variables. From the docs I should be able to tell envsubst to only replace certain ...
4
votes
4answers
419 views

How to obtain grep exit status into a variable

I started learning Bash a couple of days ago. I'm trying to obtain an exit status of grep expression into a variable like this: check=grep -ci 'text' file.sh and the output that I got is No ...
1
vote
1answer
40 views

how to change contents of one column in a file?

I have a file that looks something like that: 1 mm10_rmsk exon 67108753 67108881 239.000000 + . gene_id "RLTR17B_Mm"; transcript_id "RLTR17B_Mm"; 1 mm10_rmsk exon 134217652 ...
2
votes
1answer
31 views

How to extract IP and URL from a log file

I have a long and generic squid log file. My boss is asking me to extract IP's alongside with accessed URLs. So far I can process IP's, but I need those IP's listed with the URLs accessed. Something ...
1
vote
2answers
40 views

Compute Sum Of Date

A third party script we use pulls information based on the number of minutes a certain job runs for. I need to enter this input in the script. E.g Here is an example export etool_start=`date +"...
0
votes
1answer
37 views

how to properly pass _set_ of parameters with spaces into shell function

My problem is not simple passing parameters with spaces (I know how to achieve that), consider more complicated case: function build() { make CC="$1" CFLAGS="$2" $* # $* is not correct here! } ...
2
votes
4answers
268 views

New line in variable

I want to create a config file with a .sh file. I can't figure out how i insert new lines. The code i already have: domainconf='<VirtualHost *:80>\n ServerName '$fulldomain'\n DocumentRoot '$...
1
vote
0answers
26 views

Should I quote variable when passing to command? [duplicate]

I always do this when passing variable to command mkdir -p "$dir_to_make" are those quotes needed? I tried to google but didn't find much. I always write them, just interested if they are necessary....
3
votes
1answer
207 views

How do I access a folder which I can't sudo cd into?

I'm trying to change my directory to /boot/efi, but running sudo cd /boot/efi does nothing. I'm on fedora 23. Is there a more powerful command for this?
1
vote
2answers
92 views

Merging contents of multiple .csv files into single .csv file

I want to write a script that merges contents of several .csv files in one .csv file, i.e appends columns of all other files to the columns of first file. I had tried doing so using a "for" loop but ...
3
votes
1answer
368 views

Delete all files with executable permission in a directory

I am in need of deleting all executable files from a directory. My directory contains some configuration files and executable files, and I need to delete all executable files that I don't want. For ...
0
votes
1answer
57 views

Display Date Command

Need to export variable with date command and need the format like this export etool_start=`date +"%Y%m%d%k%M echo $etool_start 201607032314 This works fine when date digits are between 10-20. When ...
2
votes
1answer
142 views

Why can't I run a command as a user having /bin/false as login shell?

I attach to a docker image where user has already been created with this command: RUN useradd -r -u 200 -m -c "nexus role account" -d /nexus-data -s /bin/false nexus I wanted to run a command as ...
5
votes
2answers
263 views

no null in /dev error

I executed the following line: which lsb_release 2&>1 /dev/null Output: error: no null in /dev When I verified the error using the ls /dev/null command, null was present in /dev. Why is ...
-1
votes
0answers
12 views

triggering file transfer with a criteria for time and validity of file with the specific words

i want monitor directoryX/folderA for new files and trigger a copy of all those files that have a specific list of words/ headers in the first line of my file to a different directoryY/folderB . And ...
2
votes
1answer
31 views

Print stderr only if nothing gets written to stdout, otherwise print just stdout discarding stderr

There's a command that always prints stuff to stderr. Such information is never useful except when it doesn't write anything to stdout. So, is there a simple shell way, tool or command to help ...
1
vote
1answer
48 views

Initilization script runs twice on SSH

Running Ubuntu 12.04. I have a script that sets up the environment, its run by /etc/bash.bashrc. (It may be set to run by other shell profiles inits, I didn't actually set it up myself) When I Ctr+...
2
votes
2answers
37 views

Measure execution time of a command including expansion of command substitution

How would I go about measuring the running time of commands that are expanded by the shell? For example: ➜ time sleep $(sleep 3; echo 1) sleep $(sleep 3; echo 1) 0.00s user 0.00s system 0% cpu 1....
0
votes
0answers
20 views

find lastly zipped file in a directory which has so many zip files [duplicate]

I am trying to make a script in that i need to execute a command which can give me the lastly zipped logfile(ex:my log file is going to be zipped toady so i need to place this file in script.likewise ...
14
votes
5answers
628 views

Find files that contain multiple keywords anywhere in the file

I'm looking for a way to list all files in a directory that contain the full set of keywords I'm seeking, anywhere in the file. So, the keywords need not to appear on the same line. One way to do ...
1
vote
1answer
35 views

read the file and assign the values to another file

I want to read the file and assign the values to variables whic is in another file using shell script. For example I have file as "myconf" cli="/opt/Solartis_Monitoring/JON_CLI/bin/rhq-cli.sh" user="...
0
votes
1answer
37 views

how to change colors of my ps1 root terminal permanently [duplicate]

I want to change the colors of root@MyComputer:~#and when i type the ls command show me the result as colors! I write a simple BB code to display what i want: [color=red]root@MyComputer:[/color][...
3
votes
0answers
32 views

Umask value isn't reflected after making changes

I changed umask from 002 to 007 in /etc/bashrc and in /etc/profile. After logging as a normal user I run umask, and it displays 0027. It should display 0007, but it doesn't. What should I do? if [ $...
1
vote
0answers
40 views

unable to set GOPATH, despite beign set! [closed]

Edited: I found the reason! all of this was caused by an inapprotriate use of the sudo command while making directories and installing the GoLang language from the git repository. By using the ...
1
vote
1answer
29 views

List names of aliases, functions and variables in zsh

I need a way to list the names (without the body/content/value) of aliases, functions, variables, arrays in zsh. Optimally its behave like compgen: compgen -a # will list all the aliases you could ...
0
votes
3answers
25 views

Separating command arguments from flags

Say I have a command that takes flags and arguments, like this: mycommand --foo bar arg1 arg2 (The foo flag has a value of "bar".) But what if the foo flag can optionally be supplied with no ...
1
vote
1answer
57 views

How do I rename files that have '|' in them?

I am using Fedora 24. I have tried many different ways to do this. I've tried it under a Windows VM with the folder in question as a shared folder. I've tried using the 'rename' command. I've ...
1
vote
1answer
70 views

Why is find not listing matching files when preceded by an asterisk(*)? [duplicate]

On Ubuntu 14.04, 64 bit, I have set /lib/modules/4.2.0-27-generic/kernel/drivers to be my current directory. I intend to search all files having net present as a sub-string. If I search with a regex ...
0
votes
2answers
94 views

How do I record all terminal input and output to a local file by default for each session?

I'm aware the script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my ...
3
votes
2answers
71 views

confused with awk and shell variables

I am trying to run a script that uses awk. There is no error it seems, but it doesn't create the file that I want. This is the script: #!/bin/bash echo "Number of domain:" read number echo "Domain ...
-1
votes
1answer
44 views

for loop # usage

I am trying to understand how this piece of code works: for b in `git branch -r`; do git branch --track ${b##upstream/} $b; done In particular, the part where it does ${b##upstream/} I know it ...
0
votes
2answers
84 views

Why is the default shell on my Ubuntu 14.04 bash?

Some said that Ubuntu 14.04's default shell is dash. Mine is bash. My /bin/sh is dash. I don't remember if I changed the default shell. What is some way to change the default shell? Can I find out ...
2
votes
1answer
53 views

How can I decompress and print the last few lines of a compressed text file?

I have 6 gzipped text files, each of which is ~17G when compressed. I need to see the last few lines (decompressed) of each file to check whether a particular problem is there. The obvious approach is ...
0
votes
0answers
12 views

How to recover a screen session?

I'm running a screen session and it seems it hung up somehow. 0 ✓ user@hoster ~ $ screen -ls There are screens on: 30418.pts-2.hoster (Detached) 1 Socket in /run/screens/S-user. However, when I ...