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)

0
votes
1answer
9 views

Emptying a log file getting updated with 2>&1 output redirection

I have a server which constantly writes outputs and errors to stdout and stderr. The command line I use for running my server is: Server options-list > log.txt 2>&1 & Now the problem ...
0
votes
1answer
18 views

Printing Space Between Strings

#!/bin/bash ARRAY="185.18.207.66 31.18.212.113" result="" for i in $ARRAY do result=$(printf '%s %s' "$result" "$i" "checked") done paste <(printf "%s\n" $result) I am trying to print ...
0
votes
1answer
15 views

Shell script getting 'permission denied' despite using umask 000 before command

I have a shell script (build.sh) that ends by attempting to copy some files into a new directory. However it says: mkdir: cannot create directory ...
1
vote
1answer
18 views

variable doesn't change after find & while [duplicate]

My code var=34 find $1 -type f | while read line; do file_status=`file "$line"` file_name=`echo $line | sed s/".*\/"//g` line_length=${#file_name} if [ $line_length ...
1
vote
2answers
66 views

Escaping in bash

Given a text message, I need to programmatically generate a bash command to open terminal emulator and show this text in it. For example, for HelloWorld input string I need to return the following ...
0
votes
0answers
26 views

How to convert the timestamp to readable date format [duplicate]

$timestamp="160402074632" Dates=$timestamp +"%Y-%M-%D" I want this to be converted to a readable date format like “Thu Dec 9 12:50:32 CET” and store it in Dates variable if i give echo $Dates , i am ...
5
votes
2answers
349 views

Wait for stdout stream to finish and then add its contents to a file

I am trying to run a command in bash where I have a command 1 which accepts a large amount content through stdin and then outputs that content to a file.txt, however, command 1 generates a stream of ...
7
votes
2answers
180 views

What are the security issues and race conditions in using `find -exec`?

From the find man page: -exec command ; There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead. -execdir command {} + ...
0
votes
2answers
29 views

Extracting a certain folder from a tarball - how do I tell it where to put the file once extracted?

I've looked around at multiple sources for this question and I know how to extract the file, but neither source told me how to state where to put the folder once it has been extracted. I tried this: ...
0
votes
1answer
16 views

Excluding files whilst using tar to zip site contents not working [on hold]

I'm trying to zip the contents of a site using tar and exclude a bunch of folders and error_log files but it doesn't seem to be working, when it's processing I still see many of the excluded files ...
-1
votes
1answer
51 views

Organize a file [on hold]

I want to thank the great help and support. Well, I have the following file: name id alello chr pos snp s1 215 a 1 11 a215 s1 216 a 1 11 a216 s1 217 ...
2
votes
4answers
43 views

How do I echo a string with multiple spaces in bash “untouched”? [duplicate]

I assigned a var like this: MYCUSTOMTAB=' ' But using it in echo both: echo $MYCUSTOMTAB"blah blah" or echo -e $MYCUSTOMTAB"blah blah" just return a single space and the rest of the ...
3
votes
4answers
66 views

How can I save the output of “echo -e '\e]4;40;?\a'” into a variable, or pipe it?

Inspired by this forum post, I ran this command at a Bash prompt: echo -e '\e]4;40;?\a' Which outputs: # 4;rgb:8b8b/cdcd/0000 But the weird thing is, the output somehow becomes my prompt's next ...
0
votes
5answers
99 views

How do I display all the characters between two specific strings?

I want to display all the characters in a file between strings "xxx" and "yyy" (the quotes are not part of the delimiters). How can I do that ? For example, if i have input "Hello world xxx this is a ...
21
votes
1answer
960 views

Opening Your Command Prompt In A Text Editor - What Is This Called?

One of my favorite tricks in Bash is when I open my command prompt in a text editor. I do this (in vi mode) by pressing ESC v. When I do this, whatever is in my command prompt is now displayed in my ...
1
vote
1answer
33 views

Interactive remove files listed with paths in text file

I am trying to interactively remove files listed with their paths in a text file. The command I am trying is: xargs rm -i <filelist.txt The error I get is: rm cannot remove ...
1
vote
0answers
35 views

Add bash to base Linux Kernel?

We have a proprietary SBC (Single Board Computer) type of platform that is a large sized scale Raspberry Pi essentially. It is ARM based and uses Linux Kernel v3.# as its base. This isn't an Ubuntu ...
1
vote
3answers
28 views

Remove front-slash using sed

I have a text file that contains following https://git.centos.org/git/rpms/abc.git https://git.centos.org/git/rpms/abc.git/ https://git.centos.org/git/rpms/abc When I run the following command, ...
0
votes
1answer
33 views

sed cannot insert if a file ends with empty line

I have a file uca.xml (Thunar configuration for custom actions): <?xml encoding="UTF-8" version="1.0"?> <actions> <action> <!--some code--> </action> ...
0
votes
2answers
33 views

How to handle space character in input from user

I have recently started working with Shell scripting. So, I am facing one issue that when i am taking filename as an input from user, then if I give spaces then it does not get handled with my code. ...
-2
votes
0answers
14 views

Will zip -r command on remote server be cancelled if I exit terminal? [duplicate]

I have done a lot of Googling, and cannot find an answer. I have made a "zip -r home" request on my server via my terminal. The home directory is over 30GB. I need to leave the office at some point ...
-1
votes
2answers
20 views

collect and create tab separated matrix

I have 6 text files (each corresponds to a specific sample) and each file looks like this: Gene_ID Gene_Name Strand Start End Length Coverage FPKM TPM ENSMUSG00000102735 Gm7369 + ...
0
votes
1answer
32 views

syntax error: invalid arithmetic operator (error token is “.c”)

I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the ...
3
votes
4answers
62 views

How to execute multiple commands remotely on few servers?

I am trying to automate these steps so that I don't need to do this on every machines manually. I need to install latest app server software (abc.tar.gz) on all the unix boxes. I need to do this in ...
4
votes
1answer
53 views

Automatically open text files in editor instead of attempting to run them?

When I accidentally type the name of a text file without some kind of editor command, and the text file is not a shell script, I get a "permission denied" error*, since the file is not executable, and ...
1
vote
2answers
42 views

how to kill job in background?

I know how to kill a job with kill %(number) but is it possible to kill a job as background job, the question is "kill tail as a background job?"
0
votes
2answers
23 views

BASH How to save the output of rm -vri to a var [duplicate]

How can I save the output of this command into a var and still remove the files? rm -vri files | wc -l
0
votes
2answers
28 views

/usr/bin/find invocation doesn't work when used with command substitution [duplicate]

In a script, I have: CMD='/usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; ' MD5=$("${CMD}") But the script gives the error: -bash: /usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; : ...
0
votes
0answers
13 views

Update ksh file in Unix [closed]

I need to update ksh file in Unix from another file. In file that should be updated I have export RC_DB_USER=FVT2 export RC_DB_PASSWD=FVT2 export RC_DB_INSTANCE=P3ABPF2 It should be updated with ...
-1
votes
0answers
11 views

YumRepo Error in CentOS

when I run yum install lftp I get this error Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile YumRepo Error: All mirror URLs are not using ftp, http[s] or file. ...
-3
votes
3answers
29 views

unable to scp a file with a space in name [duplicate]

Actually the problem is that on the image bellow.
3
votes
4answers
75 views

How do I extract a long listing field?

I want to extract the access day of a file in a shell script. I tried by writing the following script but it doesn't work. When I echo accessday, the output is "staff". file=$1 accessday=$(ls -lu ...
0
votes
3answers
47 views

Why is the array empty after the while loop? [duplicate]

I try to initialize an array in bash-4.2 next way: ring=() ls -las | tail -n +4 | while read line > do > ring+=("$line") > echo ${ring[-1]} > done 3924 -rw-r--r-- 1 username group 4015716 ...
16
votes
5answers
1k views

Root shell mistakenly changed. How can I change it back to a valid shell?

I mistakenly entered chsh -s /usr/bin instead of chsh -s /bin/bash and now I can't log into a root shell, how do I start a bash shell as root manually ?
1
vote
1answer
23 views

Executing shell script parallelly and in background skips some operation

del_client.sh --delete client1 & del_client.sh --delete client2 & del_client.sh --delete client3 & del_client.sh --delete client4 & When I executed the commands above in the ...
-1
votes
1answer
38 views

Unable to execute shell from web server

When ever I am trying to execute php script from web server, it fails: cat test.sh echo "Hello World" [root@yumserver ~]# I am trying to build a button on webpage through which I can push the ...
1
vote
1answer
24 views

Which shells have functions where “local” does not alter exported variables for child processes?

In the example below, an exported variable is re-set as local in a function. Bash, Zsh, Fish don't pass on the original value to the child process. Are there any shells that make local affect the ...
-1
votes
0answers
21 views

Perl sqrt, cube issue: 1 showing up after each line [migrated]

I am having a tiny issue with a small perl script using arithmetic operators. After my cube root, and square root operators, a 1 shows up. I was testing this script on an openSUSE 42.1 VM. I'm just ...
0
votes
1answer
28 views

linux - setting order in which files are read or output with utilities (sorting)

I'm having issues with programs reading files in the wrong order, and also outputting in an undesirable order with utilities such as ls. I've tried some of the LC_COLLATE options, but none of them ...
1
vote
4answers
64 views

How to break a long string into multiple lines in the prompt of read -p within the source code?

I am writing an installation script that will be run as /bin/sh. There is a line prompting for a file: read -p "goat can try change directory if cd fails to do so. Would you like to add this ...
1
vote
1answer
32 views

Bash: How to get a value from an array to create command from it

Is it possible to use bash to fetch a string from an array provided in the following syntax within a config file? | | Version | PackageManager | Webserver | Database | ...
0
votes
0answers
21 views

Closing all pipes of a process [migrated]

I am working on making a program that will act in a similar way as a shell, but supports only foreground processes and pipes. I have multiple processes writing to the same pipe and some other ...
0
votes
1answer
30 views

How to execute a command for all mp3 files in a directory? [duplicate]

I have a directory with some mp3 files. I want to remove (almost) all ID3 tags using mid3v2 <file> --delete-frames=AENC,APIC,... for every mp3 file in the directory. Other files should not be ...
2
votes
5answers
147 views

Have the ls command behave differently based on the number of entries

Is it possible to have the ls command behave differently based on the number of directory entries that may be listed? If I just use ls (with no modifying options, but I can specify directories or ...
1
vote
3answers
111 views

bash / sh script to replace text between some tags/strings in a text file

I am creating executable which will be executed with /bin/sh or /bin/bash script, I have a file which contains a structure like, there will be only one #start and #end tag in the config file, and I ...
0
votes
1answer
50 views

How to run gnome javascript extensions (gjs) from terminal

I created an extension for gnome shell and want to be able to start it using a keyboard shortcut (something like ctrl+space). I didn't find good documentation or tutorials that helped me creating the ...
1
vote
1answer
34 views

Changing Shell to /bin/bash without root access via file [duplicate]

lets assume I am user(with no rights) and I need to change my shell as a default to /bin/bash by editing a file. So where I can find a file for a specific user where I can edit my default shell and ...
2
votes
1answer
26 views

What does [vmuser@localhost ~]$ mean?

What does the vmuser, localhost, ~, and $ mean in: [vmuser@localhost ~]$
1
vote
5answers
46 views

Running commands on several files and giving each output a unique name

I want to run a script on all the files in a folder like this: sh script.sh *.fasta > output however I want the outputs to be in individual files for every input. So instead of getting 5 files ...
-1
votes
0answers
18 views

Shell function to return nested JSON property [duplicate]

I'm looking to write a shell function to return single nested property value from an input json file. The format of the json file cookie.json is "personalizationID": { "expires": null, ...