PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

Saturday, November 12, 2022

[FIXED] How to install Memcached on Xampp Mac

 November 12, 2022     macos, memcached, php, terminal     No comments   

Issue

I need to use Memcached in XAMPP because I need to develop locally, and all solutions i've seen so far, dont work.

Fatal error: Class 'Memcached' not found in /Applications/XAMPP/xamppfiles/htdocs/system/libraries/Session/drivers/Session_memcached_driver.php on line 108
A PHP Error was encountered

Severity: Error

Message: Class 'Memcached' not found

Filename: drivers/Session_memcached_driver.php

Line Number: 108

Backtrace:


//does not work, and actually i need this not the bottom one.
//keep in mind that the service is running, and everything was succesfully
//installed with brew

$this->_memcached = new Memcached();


//works
$this->_memcached = new Memcache;


Solution

Found the solution :)

brew install libevent
brew install autoconf
brew install libmemcached

//Download the PHP version you are using and past it to:
cd /Applications/MAMP/bin/php/php5.6.7/include/php

//Configure the source with
/Applications/MAMP/bin/php/php5.6.7/include/php/configure

//go to
cd /Applications/MAMP/bin/php/php5.6.7/bin

//compile memcached
./pecl install memcached

//go back
cd ../

//Add the memcached.so extension to your php.ini file
echo -e "\n[memcached]\nextension=memcached.so" >> conf/php.ini

//start memcached server
memcached -m 24 -p 11211 -d

//restart MAMPP and thats it!



Answered By - Bruno Mota
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, November 10, 2022

[FIXED] How to upgrade util-linux from 2.32.1 to 2.34 in Redhat

 November 10, 2022     linux, redhat, terminal     No comments   

Issue

Is there a way to upgrade package util-linux 2.32.1 to version 2.34 on RHEL 8.5. Version 2.34 has many more output columns available for lsblk compared to 2.32.1 that I would like to use.

Searching the repo shows I have the latest.

Updating Subscription Management repositories.
Last metadata expiration check: 2:29:02 ago on Mon 16 May 2022 06:44:33 PM EDT.
Installed Packages
util-linux.x86_64                     2.32.1-35.el8                     @rhel-8-for-x86_64-baseos-rpms
Available Packages
util-linux.x86_64                     2.32.1-8.el8                      rhel-8-for-x86_64-baseos-rpms 
util-linux.x86_64                     2.32.1-17.el8                     rhel-8-for-x86_64-baseos-rpms 
util-linux.x86_64                     2.32.1-22.el8                     rhel-8-for-x86_64-baseos-rpms 
util-linux.x86_64                     2.32.1-24.el8                     rhel-8-for-x86_64-baseos-rpms 
util-linux.x86_64                     2.32.1-27.el8                     rhel-8-for-x86_64-baseos-rpms 
util-linux.x86_64                     2.32.1-28.el8                     rhel-8-for-x86_64-baseos-rpms 
util-linux.x86_64                     2.32.1-35.el8                     rhel-8-for-x86_64-baseos-rpms 

Solution

Had to clone this repo https://github.com/util-linux/util-linux.git

Then follow this how-to found here.

https://github.com/util-linux/util-linux/blob/next/Documentation/howto-compilation.txt

lsblk --version
lsblk from util-linux 2.38.141-581b1


Answered By - m0ng00se
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, November 8, 2022

[FIXED] How do I set up an alias for the terminal command 'chromium-browser'?

 November 08, 2022     alias, browser, html, linux, terminal     No comments   

Issue

At the moment, to test my webpage, I run the terminal command: chromium-browser index.html What are some more efficient alternatives?

Chromium Projects shows the following:

Chromium Projects resource


Solution

Yes, as you suggest in the title, you can setup an alias:

alias cbi='chromium-browser index.html'

Then, next time, just type cbi.



Answered By - treuss
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, October 31, 2022

[FIXED] Why does the Linux(?)-Terminal not "consume" '\n' EOF?

 October 31, 2022     c, eof, getchar, stdin, terminal     No comments   

Issue

From what I've read, the Linux terminal (in default settings) buffers the input and only sends it after receiving either EOF or '\n'.

When I loop c = getchar(); and check each c for being EOF (end then break) I need to do CTRL-D twice in order to stop reading, as the first EOF is always consumed by the terminal (I know one can change the terminal to raw, but maybe this is a bit overkill).

However, when I check for c being '\n' (which also sends the input) it will not be consumed.

Example:

  • Input: "abc\n"
    • Characters read: 'a','b','c','\n'
  • Input: "abc" and Ctrl-D
    • Characters read: 'a','b','c'
  • Input: "abc", Ctrl-D and Ctrl-D again
    • Characters read: 'a','b','c',EOF
  • Input: "abc", Return and Ctrl-D
    • Characters read: 'a','b','c','\n',EOF

Isn't this highly inconsistent? Or is there any rationale behind it?

I want to parse input including whitespaces and thus cannot check for '\n' but for EOF - is that possible without changing the terminal to raw?

I've tried with feof(stdin) too, but apperently this doesn't work either :/


Solution

That's not how it works. ^D sends on the currently buffered line, so if you don't hit it immediately after a newline, your program will not see an empty read and will not know the input is ended. So you need another ^D to send nothing. But your program never sees a ^D.

In fact you can use stty to change the terminal's EOF character, so that for example ^N will end the input; your program will run exactly the same, because it does not depend of the value of the EOF keyboard character.

PS. Since you were trying to write a C program: the input calls return EOF when they try to read a file, and get an empty buffer (0 characters). In fact, EOF is not ^D as you imagine, but -1: This value was chosen because it does not fit in a byte, while read() could legally return any possible byte (yes, even '\04' aka ^D). This is why the signature of getchar() says it returns an int.



Answered By - alexis
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, October 30, 2022

[FIXED] How to check if a file have been complete and reach to EOF?

 October 30, 2022     bash, eof, terminal, unix     No comments   

Issue

My collaborator was processing a large batch of files, but some of the output files seem to be interrupted before they were completed. It seems that these incomplete files do not have the end of the file character (EOF). I would like to do a script in batch to loop through all of these files and check if the EOF character is there for every one of the ~500 files. Can you give me any idea of how to do this? Which command can I use to know if a file has EOF character at the end?

I am not sure if there is supposed to be a special character at the end of the files when they are complete, but normal files looks like this

my_user$ tail CHSA0011.fastq
+
BBBBBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@HS40_15367:8:1106:6878:29640/2
TGATCCATCGTGATGTCTTATTTAAGGGGAACGTGTGGGCTATTTAGGCTTTATGACCCTGAAGTAGGAACCAGA
+
BBBBBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@HS40_15367:8:1202:14585:48098/1
TGATCCATCGTGATGTCTTATTTAAGGGGAACGTGTGGGCTATTTAGGCTTTATGACCCTGAAGTAGGAACCAGA
+
BBBBBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
my_user$

But when I do tail tho thse interrupted files they look like:

my_user$ tail IST-MES1.fastq
@HS19_13305:3:1115:13001:3380/2
GTGGAGACGAGGTTTCACCATGTTGGCCAGGCTGGTCTCGAGCTCCTGACCTCAAGTGATCCGTCTGCCTTGGCC
+
@B@FFFFFHHHHFHHIJJJJJIIJJJJJJJIJJJJGIIJJGIIGIIJJJJFDHHIJFHGIGHIHHHFFFFFFEEE
@HS19_13305:3:1106:5551:75750/2
CGAGGTTTCACCATGTTGGCCAGGCTGGTCTCGAGCTCCTGACCTCAAGTGATCCGTCTGCCTTGGCCCCCCAAA
+
CCCFFADFHHHHHJJIJJJJJJJJJJJJEGGIJGGHIIJIIIIIIJJJJDEGGIJJJGIIIJJIJJJHHHFDDDD
@HS19_13305:3:2110:17731:73616/2
CGAGGTTTCACCATGTTGGCCAGGCTGmy_user$

As you can see, in normal files my_user$ is displayed one line below the end of the file. But in these interrupted ones my_user$ is next to the end of the files. Maybe it just because the file does not end with a line breaker \n ?

I am sorry if the question is a bit confusing,

cheers, Guillermo


Solution

Yes, the difference is because in the first case the file ends with \n (new line).

BBBBBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
my_user$

In this case it doesn't have a new line so the next thing it prints is your use (actually your PS1)

CGAGGTTTCACCATGTTGGCCAGGCTGmy_user$

You can try this:

echo "CCCFFADFHHHHH"      # <--- implicitly includes newline at the end

echo -n "CCCFFADFHHHHH"   # <--- does not include newline at the end

There are actually two endline options, \r and \n and there are different standards according to your OS. I will assume you are working on linux and only \n is used. So in this example the newline character is 0x0a (number 10) in the ascii map.

If you want to know the last char of each file, you can do:

echo -n "CCCFFADFHHHHH" > uglyfile.txt
echo  "CCCFFADFHHHHH" > nicefile.txt
for file in *.txt; do 
    echo -n "$file ends with: 0x"; 
    tail -c 1 $file | xxd -p;
done;

If you want to know which files end with a char that is not a newline, you can do:

echo -n "CCCFFADFHHHHH" > uglyfile.txt
echo  "CCCFFADFHHHHH" > nicefile.txt
for file in *.txt; do 
    lastchar_hex=`tail -c 1 $file | xxd -p`
    if [[ $lastchar_hex != '0a' ]]; then
      echo "File $file does not end with newline"
    fi;
done;


Answered By - brunorey
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, October 29, 2022

[FIXED] How can I signal EOF to close stdin under the Git Bash terminal on Windows? Ctrl-D didn't work

 October 29, 2022     bash, eof, git, stdin, terminal     No comments   

Issue

I'm writing a command line tool. One of the things this tool can do (certainly not uniquely) is read it's input from stdin. I was testing this interactively (by typing input, rather than cat'ing a file in) when I noticed that I have no clue how to signal EOF to it.

I have spent an inordinate amount of time tonight Googling this and found nothing helpful. I searched SO, as well. Please feel free to point me to a duplicate question, but I did my due diligence, I promise.

EDIT: It might be helpful (?) to mention that I'm doing this on Windows. So I believe the terminal is more or less a branded MinGW?


Solution

If you're trying to send EOF to a program's input under Windows, Ctrl-Z is what you're looking for.



Answered By - Brendan Dolan-Gavitt
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, October 19, 2022

[FIXED] How to call a function in a new terminal, inside a bash script?

 October 19, 2022     bash, function, terminal     No comments   

Issue

I've written a script in which I define a function and later I call that function in a new terminal. Something like this:

#!/bin/sh

my_func(){
  echo "hello world"
  sleep 5
}

alacritty -e my_func

But I got an error :

[ERROR] [alacritty_terminal] Failed to spawn command 'my_func': No such file or directory (os error 2)

I guess that new terminal doesn`t have access to the function I've defined inside the script. How can I get around this?


Solution

alacritty -e will run a Linux command and you are giving it a function as an argument so it will not work.

The only way to make it work is splitting it into two scripts. I called them echo.sh and function.sh.

echo.sh

echo "Hello man"
sleep 5

function.sh

#!/bin/sh
alacritty -e ./echo.sh


Answered By - iker lasaga
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, October 6, 2022

[FIXED] How to convert sqlite to sqlite3

 October 06, 2022     sqlite, terminal     No comments   

Issue

how to convert sqlite data base to sqlite3? Can someone help me please I use windows and Mac hello everybody how to convert sqlite data base to sqlite3? Can someone help me please I use windows and Mac


Solution

SQLiteStudio can do that for you. It handles all differences between SQLite 2 and SQLite 3 on the fly. Just add SQLite 2 database to SQLiteStudio, then right-click on the database and pick "Convert database type". Then pick output file to write new SQLite file into and confirm the dialog window. That's all.



Answered By - Googie
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to setup multiple flutter versions on mac?

 October 06, 2022     flutter, macos, macos-big-sur, terminal     No comments   

Issue

I want to install both flutter v1.22.6 and v2.0.5 on my mac.

currently I have v1.22.6 set up on my mac and have path for it set aswell.

I want a setup where if I enter the command flutter doctor that corresponds to v1.22.6 and when I enter the command flutter2 doctor that corresponds to v2.0.5

enter image description here

I am new to the terminal can someone please help? as of now flutter doctor corresponds to v1.22.6 only. I tried setting a path for flutter2 but that shows as no command found

enter image description here


Solution

You need to create alias

  1. Navigate to your home directory:

    cd ~

  2. Open up .bash_profile using vi:

    vi .bash_profile or vim .bash_profile

  3. Add an alias (press i):

    alias flutter2="~/place_of_folder/flutter2/bin/flutter"

  4. Save the file (press Escape, type :wq, and hit Enter)

  5. Restart Terminal



Answered By - Nuts
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to fix permission being denied when installing Angular Client on MacOS?

 October 06, 2022     angular, macos, node.js, terminal     No comments   

Issue

I am a new coder trying to get started with Angular and Node following a tutorial on Udemy. I have successfully (I think) installed Node.js and I'm running version 16.15.1 but when I try to install the angular client it fails every time (screenshot attached). Please could someone point out where I am going wrong?

FYI my name is Manraj and I am the only user on my mac (hence I am an admin) so that is why it appears in the code as Manrajs MBP as that is the name of my laptop.

Last login: Tue Jun 21 15:35:36 on ttys000
[manrajsandhu@Manrajs-MBP~ % node
v16.15.1
(manrajsandhu@Manrajs-MBP ~ % pm itstall -g @angular/cli
pm WARN config global
--global
--local
are deprecated. Use
npm
ERRII
code EACCES
npm
ERR syscall rename
npm
RR
path /usr/local/lib/node_modules/@angular/cli
npm
ERR
dest /usr/local/lib/node modules/@angular/.cli-G39XYeT9
AR
errno -13
-location=global
instead.
npm
nom
PRR
non
SRR
npm
npm
-RR
•RR
npm
RR
npm
nom
ERR
ERD
nom
RR
Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/@angular/cli'
->
[Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/@angular/cli'
"/usr/local/lib
errno: -13,
"/usr/local/1
code: 'EACCES
syscall: 'rename'
path: '/usr/local/lib/node_modules/@angular/cli
dest:'/usr/local/lib/node_modules/Cangular/.cli-639XYeT9'
npm
ERR
npm
ERRI
npm
ERRI
npm
ERR
The operation was rejected by your operating system
It is likely you do not have the permissions to access this file as the current user
npm
RR
npm
ERR
npm
If you believe this might be a permissions issue, please double-check the
permissions of the file and its containing directories,
the command again as root/Administrator
or try running
nom
ERRII
mpm
EDD
A complete log of this run can be found in:
/Users/manrajsandhu/.npm/_logs/2022-06-21T14_36_16_571Z-debug-0.10g
manrajsandhu@Manrajs-MBP
%


Solution

You need root privileges. Just use sudo.

sudo npm install -g @angular/cli


Answered By - piotreknow
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why does apt-get consume stdin when it installs something but not otherwise?

 October 06, 2022     buffer, command, command-line-interface, shell, terminal     No comments   

Issue

I am connected to a remote Debian system via macOS Terminal.

Command after apt-get never runs if apt-get installs something

At first, I copy these three commands from a text file on my macOS and paste it into the terminal with a single command+v press:

sudo apt-get -y remove tree
sudo apt-get -y install tree
echo hi

Here is what I see in the Terminal.

lone@lone:~$ sudo apt-get -y remove tree
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'tree' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
lone@lone:~$ sudo apt-get -y install tree
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  tree
0 upgraded, 1 newly installed, 0 to remove and 17 not upgraded.
Need to get 0 B/46.1 kB of archives.
After this operation, 106 kB of additional disk space will be used.
Selecting previously unselected package tree.
(Reading database ... 31853 files and directories currently installed.)
Preparing to unpack .../tree_1.7.0-5_amd64.deb ...
Unpacking tree (1.7.0-5) ...
Setting up tree (1.7.0-5) ...
Processing triggers for man-db (2.7.6.1-2) ...
lone@lone:~$ 

The third command, echo hi, was never executed. Why?

Command after apt-get does run if apt-get does not install anything

Next time, I simply paste these two commands with a single command+v press:

sudo apt-get -y install tree
echo hi

This time, since tree is already installed, apt-get does not need to install it again. This is the output I see:

lone@lone:~$ sudo apt-get -y install tree
Reading package lists... Done
Building dependency tree       
Reading state information... Done
tree is already the newest version (1.7.0-5).
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
lone@lone:~$ echo hi
hi

This time echo hi was executed. Why?

Both results are reproducible every time I perform these two sets of operations. Why does the echo hi command not run in the first example but does in the second example?


Solution

apt-get or a program called by apt-get is emptying its stdin (which happens to be the same as the shell's, where your list of commands originates).

Since you know nothing needs to be to read from the user, redirect stdin from /dev/null:

sudo apt-get -y remove tree </dev/null
sudo apt-get -y install tree </dev/null
echo hi


Answered By - jhnc
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to copy all text from the integrated vs-code terminal?

 October 06, 2022     terminal, visual-studio-code     No comments   

Issue

Is there a way to copy all the text from the integrated Visual Studio Code terminal? I have some output that I want to copy to a text file and save it.


Solution

I can just right-click in the terminal and chose Select All and then right-click and Copy. Does that not work for you?

There is an unbound command for the selection:

workbench.action.terminal.selectAll

and Ctrl+C for the copy.

If you do this a lot you could make a macro to do the whole thing: select, copy, open a new text file and paste.



Answered By - Mark
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to use vim in the terminal?

 October 06, 2022     macos, terminal, vim     No comments   

Issue

How does one setup and start using vim in the terminal on OS X?

I want to start writing my C code using vim in the terminal rather than a separate text editor. How does one get started on this?

The basics like: opening, creating, saving files via terminal using vim and writing code using vim. Also, does one compile directly using vim in the terminal?


Solution

Run vim from the terminal. For the basics, you're advised to run the command vimtutor.

# On your terminal command line:
$ vim

If you have a specific file to edit, pass it as an argument.

$ vim yourfile.cpp

Likewise, launch the tutorial

$ vimtutor


Answered By - Michael Berkowski
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to clear the entire terminal (PowerShell)

 October 06, 2022     powershell, terminal, visual-studio-code     No comments   

Issue

I had an issue. Using the clear or cls command in powershell clears only the visible portion of the terminal,I would like to know how to clear the entire terminal?

I use VSCode by the way.


Solution

To also clear the scrollback buffer, not just the visible portion of the terminal in Visual Studio Code's integrated terminal, use one of the following methods:

  • Use the command palette:

    • Press Ctrl+Shift+P and type tclear to match the Terminal: Clear command and press Enter
  • Use the integrated terminal's context menu:

    • Right-click in the terminal and select Clear from the context menu.
    • On Windows, you may have to enable the integrated terminal's context menu first, given that by default right-clicking pastes text from the clipboard:
      Open the settings (Ctrl+,) and change setting terminal.integrated.rightClickBehavior to either default or selectWord (the latter selects the word under the cursor before showing the context menu).
  • Use a keyboard shortcut from inside the integrated terminal (current as of v1.71 of VSCode):

    • On macOS, a shortcut exists by default: Cmd+K
    • On Linux and Windows, you can define an analogous custom key binding, Ctrl+K, as follows, by directly editing file keybindings.json (command Preferences: Open Keyboard Shortcuts (JSON) from the command palette), and placing the following object inside the existing array ([ ... ]):
{
    "key": "ctrl+k",
    "command": "workbench.action.terminal.clear",
    "when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
}

Using a command you can invoke from a shell in the integrated terminal:

Note: A truly cross-platform solution would require executing the VSCode-internal workbench.action.terminal.clear command from a shell, but I don't know how to do that / if it is possible at all - do tell us if you know.

  • Linux (at least as observed on Ubuntu):

    • Use the standard clear utility (/usr/bin/clear), which also clears the scrollback buffer.

    • From PowerShell, you may also use Clear-Host or its built-in alias, cls.

      • By contrast, [Console]::Clear() does NOT clear the scrollback buffer and clear just one screenful.
  • macOS:

    • Unfortunately, neither /usr/bin/clear nor PowerShell's Clear-Host (cls) nor .NET's [Console]::Clear() clear the scrollback buffer - they all clear just one screenful.

    • Print the following ANSI control sequence: '\e[2J\e[3J\e[H' (\e represents the ESC char. (0x1b, 27); e.g., from bash: printf '\e[2J\e[3J\e[H'; from PowerShell: "`e[2J`e[3J`e[H"

    • You can easily wrap this call in a shell script for use from any shell: create a file named, say, cclear, in a directory listed in your system's PATH variable, then make it executable with chmod a+x; then save the following content to it:

      #!/bin/bash
      
      # Clears the terminal screen *and the scrollback buffer*.
      # (Needed only on macOS, where /usr/bin/clear doesn't do the latter.)
      
      printf '\e[2J\e[3J\e[H'
      
  • Windows:

    • NO solution that I'm aware of: cmd.exe's internal cls command and PowerShell's internal Clear-Host command clear only one screenful in the integrated terminal (not also the scrollback buffer - even though they also do the latter in a regular console window and in Windows Terminal).

    • Unfortunately, the escape sequence that works on macOS ("`e[2J`e[3J`e[H" or, for Windows PowerShell, "$([char]27)[2J$([char]27)[3J$([char]27)[H") is not effective: on Windows it just clears one screenful.

    • (By contrast, all of these methods do also clear the scrollback buffer in regular console windows and Windows Terminal.)



Answered By - mklement0
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I add my host to known hosts manually?

 October 06, 2022     keyscan, known-hosts, ssh, terminal     No comments   

Issue

I try to add my host to known host via terminal:

ssh-keyscan -H 195.118.254.45 >> ~/.ssh/known_hosts

But when I open my known hosts file with text edit, then it is still empty. Nothing was added.


Solution

The working solution for me was:

ssh-keyscan -H -p 2222 -t ecdsa 195.118.254.45 >> ~/.ssh/known_hosts

I had to define the correct port



Answered By - peace_love
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to determine a terminal's background color?

 October 06, 2022     gnome-terminal, terminal, unix, x11     No comments   

Issue

I'd like to know if there is any way to determine a terminal's background color ?

In my case, using gnome-terminal.
It might matter, since it's entirety up to the terminal application to draw the background of its windows, which may even be something else than a plain color.


Solution

I've came up with the following:

#!/bin/sh
#
# Query a property from the terminal, e.g. background color.
#
# XTerm Operating System Commands
#     "ESC ] Ps;Pt ST"

oldstty=$(stty -g)

# What to query?
# 11: text background
Ps=${1:-11}

stty raw -echo min 0 time 0
# stty raw -echo min 0 time 1
printf "\033]$Ps;?\033\\"
# xterm needs the sleep (or "time 1", but that is 1/10th second).
sleep 0.00000001
read -r answer
# echo $answer | cat -A
result=${answer#*;}
stty $oldstty
# Remove escape at the end.
echo $result | sed 's/[^rgb:0-9a-f/]\+$//'

Source/Repo/Gist: https://gist.github.com/blueyed/c8470c2aad3381c33ea3



Answered By - blueyed
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do programs like Emacs and Nano get user input while running in terminal without the user having to press enter?

 October 06, 2022     emacs, terminal, termios     No comments   

Issue

Programs like Emacs and Nano can run in a terminal window and accept real time user input, how might I accomplish this myself? I am looking to use C++ but I can see this could require interfacing with the user's shell, in this case Bash. How can I take input (be it from the mouse or keyboard) from the terminal window without the user having to press enter?

My target platform is Mac OSX Version 10.13.5, but answers on how to do this on other platforms like Windows or Linux are also welcome.


Solution

These programs set the terminal to raw mode as opposed to cooked mode. Cooked mode is read a line at a time and is handled by the terminal driver, and raw mode is read a character at a time and is handled by the running program instead.

This Answer has more information.

This Repo is a simple project that implements this mode that you can learn from. man termios will also give you information about manipulating terminal modes.



Answered By - Major
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why does the terminal display in my vscode look different?

 October 06, 2022     terminal, visual-studio-code     No comments   

Issue

So I initially used windows, but recently decided to switch to linux. In windows, my vscode terminal look like this: enter image description here

It shows which directory I am in. But when i try vscode in linux, i get this on run:

enter image description here

It shows nothing but sh-5.1, which i don't know what is it. And when i run a simple c program: enter image description here

the output is on the same line as the sh-5.1. How to change the terminal to look like in windows? (not exactly the same, I mean at least show the directory and generate a newline when done running program)


Solution

You can simply write:

bash

to your console since bash shell is the closest one to what you want. Your current shell is sh. To switch back to sh, you can write sh again. To see other available shells in your computer, you can write: cat /etc/shells

If you don't have bash installed on your computer (which is pretty unlikely), you can install it by:

sudo apt-get install bash


Answered By - meta6483
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to move the cursor word by word in the OS X Terminal

 October 06, 2022     keyboard-shortcuts, macos, terminal     No comments   

Issue

I know the combination Ctrl+A to jump to the beginning of the current command, and Ctrl+E to jump to the end.

But is there any way to jump word by word, like Alt+←/→ in Cocoa applications does?


Solution

Out of the box you can use the quite bizarre Esc+F to move to the beginning of the next word and Esc+B to move to the beginning of the current word.



Answered By - Kristian J.
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] When I open my terminal, I receive the following message -> /Users/pankajkumar/.zshrc:[:9: ']' expected

 October 06, 2022     oh-my-zsh, terminal, zsh, zshrc     No comments   

Issue

It seems that whenever I open my terminal in Mac M1, I get this error message. I have attached a screenshot of the terminal, as well as a .zshrc file. If anyone knows the solution, please let me know.

👇 The terminal displays this information 👇

/Users/pankajkumar/.zshrc:[:9: ']' expected
pankajkumar@Pankajs-MacBook-Pro ~ %

👇 Data inside .zshrc file 👇

local brew_opt_path="/opt/homebrew/opt"
local nvm_path="$HOME/.nvm"

export PATH="${brew_path}:${PATH}"
export NVM_DIR="${nvm_path}"

[ -s "${brew_opt_path}/nvm/nvm.sh" ] && . "${brew_opt_path}/nvm/nvm.sh" #This load nvm

[ -s "${brew_opt_path}/nvm/etc/bash_completion.d/nvm"] && . "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" #This loads nvm bash_completion

export PATH="/opt/homebrew/opt/php@8.0/bin:$PATH" export PATH="/opt/homebrew/opt/php@8.0/sbin:$PATH"


Solution

Spaces matter when dealing with the brackets:

[ -s "${brew_opt_path}/nvm/etc/bash_completion.d/nvm"] && . "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" #This loads nvm bash_completion

This must be like so:

[ -s "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" ] && . "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" #This loads nvm bash_completion

Notice the space between nvm" and ].



Answered By - James Risner
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing