Skip to main content

Questions tagged [shell]

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, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

Filter by
Sorted by
Tagged with
2 votes
1 answer
626 views

Which interpreter for "Unicode text, UTF-8 text executable"

I'm trying to set up a keybinding for an executable which is in my home. For this, I set the command: sh -c '\"/path/to/the/executable\" --options' But, it does not work, and, when I'm ...
Phantom's user avatar
  • 453
-1 votes
1 answer
46 views

Taking only a four-digit number as user input

In a shell script, I'm reading user input into a variable. Before I can do anything with it, I need to confirm if the input is a 4-digit number. If not, I want to exit the program without doing ...
Rishikesh Negi's user avatar
2 votes
1 answer
40 views

Shell/bash: Can I create a file descriptor to an existing file without emptying the file? [duplicate]

Context: I have cursory bash experience. I do not fully get file descriptors, just some basic usage. Trying to create a setup script. Most done, but a few "kinks" remain. So here is a newbie ...
Marcus Widerberg's user avatar
0 votes
2 answers
24 views

Play sound after command and also pipe output

I can easily pipe the output of a command like: some_command | less I can also easily play a sound after a command like: echo test; print \\a aplay, beep or others could also be used for sound. ...
Luis's user avatar
  • 101
0 votes
2 answers
21 views

How do I update the contents of a script including comments (django/settings.py) using echo, printf or grep

I would like to overwrite a Django/app/settings.py text file using the Linux terminal command printf. The settings.py starts with docstrings comments, i.e. """some text"""...
Tommy Gibbons's user avatar
0 votes
2 answers
64 views

variable with hyphen in bash script

db1="community-service-data" db2="ecomm-data-test" drop_db="DROP DATABASE ${db1}" sudo -u postgres -S /bin/bash -c "psql -U postgres -d postgres -c \"${drop_db}...
CodeWeed's user avatar
  • 137
1 vote
2 answers
72 views

Command not found on shell opening

Every time I open the shell, the first line on the terminal is "bash: n: command not found". I tried to look at /etc/profile, ~/.bashrc, ~/.profile and ~/.bash_profile but I was not able to ...
Alessandro's user avatar
-3 votes
0 answers
56 views

Why can't I move a directory in a shell created by `adb shell`? [duplicate]

I enter a shell on Android by sudo adb shell Now I want to move a directory (of files) in Android into another, but why does it fail $ mv english/ ../mydata/ ...
Tim's user avatar
  • 103k
0 votes
1 answer
25 views

view a bunch of text files in the terminal [duplicate]

I've got a bunch of text files and pdfs in a directory. If I enter evince *.pdf ..all the pdfs open up in separate windows, I do this quite often. When I enter cat *.txt ..was pleasantly surprised ...
cardamom's user avatar
  • 592
2 votes
2 answers
200 views

find with du -sch and very many files

I have large folder structure and need to get the size of a certain subset. The directories I need to count are defined by having specific subdirectories: find . \( -iname a -or ... \) -printf "\&...
cheersmate's user avatar
4 votes
1 answer
145 views

How to check if part of a symlink goes outside a directory in posix shell

I have about 43996 symlinks in a directory and want to check if any of them at any point of their path exit that directory in a posix shell script even if the end destination falls inside the ...
Tim_Kritikos's user avatar
-1 votes
1 answer
45 views

FreeBSD Reverse Shell Command Issue: Ambiguous Output Redirect Error

I’ve been experimenting with penetration testing recently, and I need to use reverse shell techniques for testing. I’ve previously used reverse shell on Ubuntu with the following command: /bin/bash -i ...
HsingLI's user avatar
  • 11
-2 votes
1 answer
61 views

regular single column data to multiple rows

source data KKK-SNMImsi: 444444 KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile KKK-SNMMmeAddress: TDSGSN01 KKK-SNMMsisdn: 44235682436 KKK-SNMLocationState: LOCATED KKK-SNMRoamingAllowed: FALSE ...
Peter Cherop's user avatar
1 vote
1 answer
60 views

Running a cronjob that requires setting of several environment variables in particular directory

I need to setup Cron Job to run regressions for which I usually follow below steps in terminal: cd path/to/regression_dir/ source setup.csh perl "regression_script.pl" The setup.csh files ...
Rutuja14's user avatar
1 vote
0 answers
43 views

Shell: Customizing the "Display all N possibilities? (y or n)" message

I already know that double-pressing the Tab key on Bash terminal will enlist all files and folders in the current working directory or, when appropriate, show Linux executables that I can run. I want ...
groaking's user avatar
1 vote
1 answer
115 views

What is PS1 prompt \[\e]0; vs \[\e]2; , it looks like one is for title name of tab, one is for title name of windows

here is my ps1 does someone know documents about this? export PS1='\[\e]0;YYY@\h:\w\a\]\[\e]2;XXX\W\a\e[32;40m\]\[\e[36;40m\]$?\[\e[31;40m\]\D{%d}\[\e[35;40m\]\D{%H%M}\[\e[36;40m\]\W\[\e[32;40m\]>\[...
user3073309's user avatar
0 votes
2 answers
85 views

SSH shows double shell prompt after entering a command

As you can see in the example below, the shell prompt is duplicated after I use a command. I tried changing the PS1 to something simpler, but the same issue continues to occur: PS1="\u@\h:\W\$ &...
Pineapple29's user avatar
0 votes
1 answer
31 views

Saving ZSH history across SSH sessions [duplicate]

Is it possible to keep zsh history consistent across SSH sessions to the same machine? To explain further, let's say I opened an SSH session to another computer, ran mkdir test-dir/, and exited the ...
WoaItsBren's user avatar
0 votes
0 answers
48 views

How do I check the status of an LSB service? [duplicate]

If I run service --status-all I see a list of all services, including the service (let's call it X), that I'm interested in Status of X: X is running with the PID Y If I then do service status X I ...
Mark Booth's user avatar
  • 1,041
3 votes
2 answers
286 views

How do quotes work in bash regex regarding reserved characters?

Is there any special bash reserved characters in bash regex expression? ex: eg: if [[ $url =~ ^https:\/\/www\.youtube\.com\/playlist\?(.+&)?list= ]]; then echo "URL matches the regex"; ...
Nor.Z's user avatar
  • 133
-3 votes
1 answer
51 views

Watch command but with shell

I want use shell and see watch on top parallel without switching to another tty. Is theres way to do that?
      ogyrehlosiash's user avatar
0 votes
3 answers
123 views

How to add a prefix to every element of an array in shell

I am reading inputs from user in my script with spaces, and those multiple inputs I want to use in a command further down by adding -l in front of each one of those inputs. Is there a way to do this ...
Heyya's user avatar
  • 19
2 votes
2 answers
57 views

set -o xtrace for just one line? [duplicate]

bash 4.4.20(1) on RHEL 8.4. set -x ; ./blarge ; set +x works, of course, but it's just that much more stuff to remember to remove when you're finished. And gets sticky if you're running ssh, sudo, ...
RonJohn's user avatar
  • 1,134
1 vote
1 answer
58 views

How to store and source environment variables when they contain semicolon (`;`) [duplicate]

I'm trying to exchange environment variables and restore them quickly between terminals. I define two functions in my shell (~/.bashrc): save_env(){ mkdir -p ~/tmp printenv > ~/tmp/env } ...
furynerd's user avatar
0 votes
0 answers
14 views

How to assign stdout of subshells to variables in a platform agnostic way [duplicate]

I have discovered that on Sun 10, /bin/sh does not support $(...) syntax for variable assignments, with or without double quotes: -bash-3.2# uname -a SunOS unknown 5.10 Generic_147148-26 i86pc i386 ...
Shane Bishop's user avatar
0 votes
0 answers
79 views

Bash terminal lagging one input behind

After a recent update, I've noticed that working on any terminal for more than a few minutes causes a delay between inputting a keypress and seeing it reflected on the screen. Specifically, if I were ...
Nick Reed's user avatar
  • 163
0 votes
1 answer
70 views

How to delete a directory whose name has special characters

My ./imap directory contains two folders with names containing special characters : ‘No’$‘\351’‘.sbd’ ‘S’$‘\351’‘gol’$‘\350’‘ne.sbd’ (these are the full names with no other characters added). The ...
Josef's user avatar
  • 1
0 votes
2 answers
43 views

From hexdump to ascii (xxd -r stuck writing zero bytes)

To diagnose secure boot issues, I'm looking at the sbat sections of all bootloaders on a machine: sudo sh -c 'for f in /boot/efi/EFI/*/*.efi; do echo "$f"; objdump -j .sbat -s "$f" ...
Tobu's user avatar
  • 6,620
0 votes
1 answer
31 views

How to suppress warnings of MongoDB shell?

I want to parse by jq output of mongo --quiet --eval "JSON.stringify(db.adminCommand('listDatabases'))" But it returns WARNING: slaveOk() is deprecated and may be removed in the next major ...
palmasd1's user avatar
  • 125
0 votes
0 answers
55 views

Does the shell provide access to all services that an OS can provide? [duplicate]

I'm an Undergraduate CS student learning about Computer Architecture and OS. Naturally, we learnt about Unix and Linux. Recently, I came across the term "shell". My understanding and ...
user1514263's user avatar
0 votes
1 answer
15 views

how do I access Pass files when logged into my user's shell from another user's session?

I just migrated from keepassxc to the linux pass password utility. But I often find myself su'ing to my user's account from another user's session, and when I try to run any pass commands on entries ...
naphelge's user avatar
5 votes
1 answer
205 views

printf in Zsh does not shell escape exclamation mark

In Zsh 5.9, we can use printf to shell escape a string: $ printf '%q' 'One! Two' One\!\ Two This produces the correct output of escaping the ! and the space. Now let’s make it as a script: #!/bin/...
user137369's user avatar
0 votes
1 answer
48 views

Shell: How to print all files in a folder with cat with files separator [duplicate]

If I do cat * in a directory, then I cannot easily see when I switch from one file to the next. I would like to have a visual indication that the files are not the same. I tried options -n and -b but ...
Laurent Lyaudet's user avatar
0 votes
0 answers
43 views

Why doesn't "sudo -i -u user bash -c string" run as expected?

On my CentOS 7 machine, there are 5 folders in /home/nanxiao/log/: $ ll /home/nanxiao/log/ total 0 drwxr-xr-x. 2 nanxiao nanxiao 100 Feb 28 15:56 facebook drwxr-xr-x. 2 nanxiao nanxiao 102 Feb 28 15:...
Nan Xiao's user avatar
  • 1,417
0 votes
0 answers
71 views

Why are my strings being truncated including and after an equals sign?

I was writing a shell script for inserting a string value through a Microsoft sqlcmd variable into a Microsoft SQL server database table and noticed some unexpected behavior. It appeared the trailing ...
Mark's user avatar
  • 101
-2 votes
2 answers
128 views

How to make bc handle explicitly positive numbers? Or what alternative calculator can be used with such support?

Consider the following: $ echo "-1" | bc -1 $ echo "(1)" | bc 1 $ echo "+1" | bc (standard_in) 1: syntax error Minus sign and round braces are handled correctly but ...
Anton Samokat's user avatar
1 vote
1 answer
32 views

Relaunch a terminal using a terminal command

Today, to convert from Markdown to PDF using Pandoc, it was necessary to install pdflatex. I did brew install basictex and then it was necessary to relaunch Terminal. For this, I simply closed it and ...
jsx97's user avatar
  • 69
0 votes
1 answer
40 views

How to delete file and folder with irregular names

the content of some folder is like that: Folder name is empty File name is asterisk I can find inode of these file and folder OS - z/OS OMVS, so, there is no option -delete on find command How can I ...
Barat Sahdzijeu's user avatar
-1 votes
1 answer
59 views

How to specify several alternative conditions (OR operator) for single case statement? (Or Alternatively, where is shell case syntax description?) [duplicate]

I want something like this: time="1m" case "$time" in *h*) *m*) *s*) echo "handling several cases for h, m, s tokens" ;; *) echo "...
Anton Samokat's user avatar
0 votes
5 answers
88 views

How can I replace the last occurrence of " before ] (text-manipulation)

I'm doing some text manipulation and I want to replace the last occurrence of " (with ", "four") before ] which could be in different lines. (this essentially adds a new item in ...
kyles's user avatar
  • 33
1 vote
1 answer
39 views

How do I tell if my shell is being run from within Dolphin's integrated terminal?

I'd like to choose whether or not to load zsh plugins if the shell is, at the moment, being run within Dolphin. Is this possible? I've considered: ps: ps, at least without any flags, does not seem to ...
Ernest Izdebski's user avatar
1 vote
3 answers
70 views

How can I add a property in the end of the object (text manipulation)

I'm doing some text manipulation and I want to add a property (at the end) to an object named "object" that is inside a configuration file e.g . . object = { "one": "one&...
kyles's user avatar
  • 33
5 votes
1 answer
499 views

Root couldn't write to file with rw permissions for all users and owned by other user

I have script that can be runned from different users on the same machine. This script should write logs to the same file on every run. Minimal version of script: #!/usr/bin/env bash ...
armoken's user avatar
  • 53
0 votes
1 answer
62 views

Unable to get cURL command to run within a script with variables

I have what I thought was a simple script: #!/bin/sh URL=myserver:9443 myCmd="curl -sS -k -X 'POST' 'https://" myCmd+=$URL myCmd+="/SKLM/rest/v1/ckms/accessToken' " myCmd+="-...
NCDeveloper's user avatar
-2 votes
1 answer
71 views

Behavior of truncating multiple slashes in paths stemming from glob pattern matching

From my limited research it seems that in bash, any multiple slashes after a glob pattern are truncated, like so: echo ////[h]ome////user////Desktop////test//// # outputs ////home/user/Desktop/test/ ...
GhtGhoster's user avatar
1 vote
1 answer
23 views

zsh completion for custom script: URL + optional parameters

I have zsh completion for custom script, where one parameter must be URL (ie, string) and then there are several optional parameters: --AAA --BBB --CCC: _arguments -S : \ '--AAA' \ '--BBB' \ ...
Martin Vegter's user avatar
1 vote
0 answers
33 views

Send Input to Interactive Process via File Descriptor

How can I find the file descriptor that a process reads input from? Background I run a Vite (pronounced veet) server when developing in an Alpine container. Currently I login to the container and ...
b01's user avatar
  • 4,514
-2 votes
1 answer
174 views

Error in command su

I am creating a command that will change a certain line in the /etc/profile file from a script, however in certain versions of Linux the sudo command may not be activated so it would be necessary to ...
user avatar
0 votes
1 answer
44 views

SIGTSTP(Ctrl-Z) not working for script started by script command

Note: script refers to the script command, which logs stdin and stdout to files. I was trying to run a script with the script utility to save output for later inspection while preserving text colors ...
GoDaft WithEBK's user avatar
0 votes
2 answers
82 views

access shell alias with dmenu

I have a collection of bash commands (one liners) that I use on a regular basis to open new shells or start programs with a given set of arguments. As I use dmenu, I'd like to be able to use those ...
PinkFloyd's user avatar
  • 429

1
2 3 4 5
243